libtins icon indicating copy to clipboard operation
libtins copied to clipboard

Unresolved external symbols on MSVC

Open gardc opened this issue 3 years ago • 3 comments

I am trying to get my compiled libtins working on Windows without any luck. I've followed the download and installing guide. Compiles libtins from build/libtins.sln without any problems, though it only gives a x64 solution platform whereas I'm going to use it for building a 32bit executable. I'm not sure whether that matters.

When including libtins in my test code, I am getting these errors:

main.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall Tins::PDU::~PDU(void)" (??1PDU@Tins@@UAE@XZ) referenced in function "public: virtual __thiscall Tins::EthernetII::~EthernetII(void)" (??1EthernetII@Tins@@UAE@XZ)
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Tins::EthernetII::EthernetII(class Tins::HWAddress<6> const &,class Tins::HWAddress<6> const &)" (??0EthernetII@Tins@@QAE@ABV?$HWAddress@$05@1@0@Z) referenced in function _main
1>...\libtins\build\lib\Release\tins.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
1>...\Debug\libtins_test.exe : fatal error LNK1120: 2 unresolved externals

main.cpp test code:

#define WIN32_LEAN_AND_MEAN
#define TINS_STATIC
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS

#include <tins/tins.h>
#include <iostream>

using namespace Tins;
using std::endl;

const int main() {
	EthernetII eth;

	std::cout << "Hello" << endl;

	return 0;
}

gardc avatar Mar 17 '21 10:03 gardc

I've followed the download and installing guide. Compiles libtins from build/libtins.sln without any problems, though it only gives a x64 solution platform whereas I'm going to use it for building a 32bit executable. I'm not sure whether that matters.

That does indeed matter and is the reason for the error you see. I don't use Visual Studio myself so I cannot guide you, but try to see if you can change the solution to build a 32-bit library somehow. That should fix your issue.

laudrup avatar Mar 17 '21 16:03 laudrup

That does indeed matter and is the reason for the error you see. I don't use Visual Studio myself so I cannot guide you, but try to see if you can change the solution to build a 32-bit library somehow. That should fix your issue.

I used either -CMAKE_GENERATOR_PLATFORM=Win32 or -A=Win32, and that generated a Visual Studio solution with Win32 as build target. But then I got an LNK1112 error specifically on address_range.obj when trying to build.

gardc avatar Mar 18 '21 02:03 gardc

I got it to build now using cmake ../ -DPCAP_ROOT_DIR=<dir> -DLIBTINS_ENABLE_WPA2=0 -DLIBTINS_BUILD_SHARED=0 -G "Visual Studio 16 2019" -A Win32 to generate the project. Should this perhaps be noted in the documentation for CMake noobs such as myself?

And as a note for others who might have problems; only the release version of libtins.lib works with release build of the lib consumer and debug lib for debug build 🤯

gardc avatar Mar 18 '21 03:03 gardc