sockpp icon indicating copy to clipboard operation
sockpp copied to clipboard

error LNK2001

Open eaglesharkmayonnaise opened this issue 4 years ago • 3 comments

  1. git clone https://github.com/fpagliughi/sockpp
  2. run Visual Studio 2019 Developer Command Prompt v16.5.4
  3. cd sockpp && mkdir build && cd build
  4. run cmake

cmake .. -G"NMake Makefiles" -DSOCKPP_BUILD_STATIC=SOCKPP_BUILD_STATIC -DCMAKE_CXX_FLAGS_RELEASE=/MT -DCMAKE_BUILD_TYPE=Release

  1. build examples/tcp/tcpecho.cpp
1>main.obj : error LNK2001: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __stdcall sockpp::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class sockpp::inet_address const &)" (??6sockpp@@YGAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV12@ABVinet_address@0@@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __stdcall sockpp::socket::error_str(int)" (?error_str@socket@sockpp@@SG?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: static void __stdcall sockpp::socket::destroy(void)" (?destroy@socket@sockpp@@SGXXZ)
1>main.obj : error LNK2001: unresolved external symbol "public: static void __stdcall sockpp::socket::initialize(void)" (?initialize@socket@sockpp@@SGXXZ)

eaglesharkmayonnaise avatar Apr 19 '20 16:04 eaglesharkmayonnaise

Apologies, I'm not much of a Windows user, but I noticed two things when I was doing some tests with Windows:

  1. I had the best success when I specified exactly what compiler I wanted to use via the Generator option.
  2. The Microsoft compiler(s) seemed to keep defaulting to a 32-bit build on a 64-bit machine. I have no idea why. But you seem to have to force a 64-bit build, and that can be different depending on which version of the compiler.

For MSVS 2019, I have been using this:

cmake -G "Visual Studio 16 2019" -Ax64 -DSOCKPP_BUILD_EXAMPLES=ON ..

I'm going to pull out a Windows machine later this week. I'll double check if there's some issue with the static build, but to my knowledge it was working fine.

fpagliughi avatar Apr 20 '20 12:04 fpagliughi

  1. cmake
C:\Users\ssss\Desktop\sockpp\build>cmake -G "Visual Studio 16 2019" -Ax64 -DSOCKPP_BUILD_EXAMPLES=ON ..
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.18363.
-- The C compiler identification is MSVC 19.25.28614.0
-- The CXX compiler identification is MSVC 19.25.28614.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Creating static library: sockpp-static
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Using library for samples: sockpp-static
-- Using library for samples: sockpp-static
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/ssss/Desktop/sockpp/build
  1. opened sockpp.sln and build it
1>------ Build started: Project: tcpechotest, Configuration: Debug x64 ------
1>tcpechotest.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.25.28610\include\random(1902,5): error C2338: invalid template argument for uniform_int_distribution: N4659 29.6.1.1 [rand.req.genl]/1e requires one of short, int, long, long long, unsigned short, unsigned int, unsigned long, or unsigned long long
1>C:\Users\ssss\Desktop\sockpp\examples\tcp\tcpechotest.cpp(92): message : see reference to class template instantiation 'std::uniform_int_distribution<char>' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.25.28610\include\random(1902,1): error C2338: note: char, signed char, unsigned char, char8_t, int8_t, and uint8_t are not allowed
1>C:\Users\ssss\Desktop\sockpp\examples\tcp\tcpechotest.cpp(106,9): warning C4244: 'initializing': conversion from 'ssize_t' to 'int', possible loss of data
1>Done building project "tcpechotest.vcxproj" -- FAILED.
2>------ Skipped Build: Project: INSTALL, Configuration: Debug x64 ------
2>Project not selected to build for this solution configuration 
========== Build: 0 succeeded, 1 failed, 12 up-to-date, 1 skipped ==========

eaglesharkmayonnaise avatar Apr 23 '20 13:04 eaglesharkmayonnaise

Oh, I think there's a fix for that in the develop branch from PR #44, originally reported in Iuuse #42.

fpagliughi avatar Apr 23 '20 19:04 fpagliughi

I don't know if this was actually foxed or not, but will attempt to recreate before the next v0.8.1 release.

fpagliughi avatar Jan 18 '23 04:01 fpagliughi

This all builds for me now with the latest release. If you are still having trouble, feel free to reopen this issue with any new information.

fpagliughi avatar Jan 18 '23 16:01 fpagliughi