Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LNK2019 when build in Visual Studio 2017 #10

Open
kxu-ffd opened this issue Jul 28, 2018 · 11 comments
Open

LNK2019 when build in Visual Studio 2017 #10

kxu-ffd opened this issue Jul 28, 2018 · 11 comments

Comments

@kxu-ffd
Copy link

kxu-ffd commented Jul 28, 2018

Hi, I am trying your solution to stream OpenCV processed images from one computer to another. However, I am stuck at the build step. It seems the VS compiler is not able to link the functions in TCPServerSocket. No issue during the cmake. I tried to modify the CMakeLists.txt to explicitly include the header files, but it does not work. Strangely, I am able to build the project in Ubuntu. The attached is the error log from VS 2017.

PracticalSocket.obj : error LNK2019: unresolved external symbol accept referenced in function "public: class TCPSocket * __cdecl TCPServerSocket::accept(void)" (?accept@TCPServerSocket@@QEAAPEAVTCPSocket@@xz)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol bind referenced in function "public: void __cdecl Socket::setLocalPort(unsigned short)" (?setLocalPort@Socket@@QEAAXG@Z)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol closesocket referenced in function "public: __cdecl Socket::~Socket(void)" (??1Socket@@qeaa@XZ)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol connect referenced in function "public: void __cdecl CommunicatingSocket::connect(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,unsigned short)" (?connect@CommunicatingSocket@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@g@Z)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol getpeername referenced in function "public: class std::basic_string<char,struct std::char_traits,class std::allocator > __cdecl CommunicatingSocket::getForeignAddress(void)" (?getForeignAddress@CommunicatingSocket@@qeaa?AV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@xz)
3>Generating Code...
2>PracticalSocket.obj : error LNK2019: unresolved external symbol getsockname referenced in function "public: class std::basic_string<char,struct std::char_traits,class std::allocator > __cdecl Socket::getLocalAddress(void)" (?getLocalAddress@Socket@@qeaa?AV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@xz)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol htonl referenced in function "public: void __cdecl Socket::setLocalPort(unsigned short)" (?setLocalPort@Socket@@QEAAXG@Z)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol htons referenced in function "public: void __cdecl Socket::setLocalPort(unsigned short)" (?setLocalPort@Socket@@QEAAXG@Z)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol inet_addr referenced in function "public: void __cdecl UDPSocket::joinGroup(class std::basic_string<char,struct std::char_traits,class std::allocator > const &)" (?joinGroup@UDPSocket@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@@z)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol inet_ntoa referenced in function "public: class std::basic_string<char,struct std::char_traits,class std::allocator > __cdecl Socket::getLocalAddress(void)" (?getLocalAddress@Socket@@qeaa?AV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@xz)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol listen referenced in function "private: void __cdecl TCPServerSocket::setListen(int)" (?setListen@TCPServerSocket@@AEAAXH@Z)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol ntohs referenced in function "public: unsigned short __cdecl Socket::getLocalPort(void)" (?getLocalPort@Socket@@QEAAGXZ)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol recv referenced in function "public: int __cdecl CommunicatingSocket::recv(void *,int)" (?recv@CommunicatingSocket@@QEAAHPEAXH@Z)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol recvfrom referenced in function "public: int __cdecl UDPSocket::recvFrom(void *,int,class std::basic_string<char,struct std::char_traits,class std::allocator > &,unsigned short &)" (?recvFrom@UDPSocket@@QEAAHPEAXHAEAV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@aeag@Z)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol send referenced in function "public: void __cdecl CommunicatingSocket::send(void const *,int)" (?send@CommunicatingSocket@@QEAAXPEBXH@Z)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol sendto referenced in function "public: void __cdecl UDPSocket::sendTo(void const *,int,class std::basic_string<char,struct std::char_traits,class std::allocator > const &,unsigned short)" (?sendTo@UDPSocket@@QEAAXPEBXHAEBV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@g@Z)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol setsockopt referenced in function "public: void __cdecl UDPSocket::setMulticastTTL(unsigned char)" (?setMulticastTTL@UDPSocket@@QEAAXE@Z)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol socket referenced in function "protected: __cdecl Socket::Socket(int,int)" (??0Socket@@iEAA@HH@Z)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol gethostbyname referenced in function "void __cdecl fillAddr(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,unsigned short,struct sockaddr_in &)" (?fillAddr@@YAXAEBV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@GAEAUsockaddr_in@@@z)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol getservbyname referenced in function "public: static unsigned short __cdecl Socket::resolveService(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,class std::basic_string<char,struct std::char_traits,class std::allocator > const &)" (?resolveService@Socket@@SAGAEBV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@0@Z)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol WSAStartup referenced in function "protected: __cdecl Socket::Socket(int,int)" (??0Socket@@iEAA@HH@Z)
2>PracticalSocket.obj : error LNK2019: unresolved external symbol WSACleanup referenced in function "public: static void __cdecl Socket::cleanUp(void)" (?cleanUp@Socket@@Saxxz)

@chenxiaoqino
Copy link
Owner

chenxiaoqino commented Jul 28, 2018 via email

@email2jie
Copy link

Looks like practical socket already uses winsock in the Socket superclass if WIN32 is defined.

@chenxiaoqino
Copy link
Owner

chenxiaoqino commented Jul 30, 2018 via email

@email2jie
Copy link

It may have to do with something is not working well with x64. I tried compiling this for windows in Visual Studios, at first it was just saying my target machine was x86. But after I changed the target machine it started to not recognize the functions. Do you know if practical socket works on x64 bit machines?

@chenxiaoqino
Copy link
Owner

chenxiaoqino commented Jul 30, 2018 via email

@email2jie
Copy link

Looks like it needs to link different libraries and uses different dlls... https://docs.microsoft.com/en-us/windows/desktop/winsock/creating-a-basic-winsock-application

tried it out and it works now

@v-prgmr
Copy link

v-prgmr commented Sep 23, 2019

@email2jie , hi , could you share what you tried out and made it work?
Thank you

@BrieoRobino
Copy link

Any plans on updating this to build in windows?

@chenxiaoqino
Copy link
Owner

chenxiaoqino commented Oct 3, 2019 via email

@AlexYiningLiu
Copy link

Looks like it needs to link different libraries and uses different dlls... https://docs.microsoft.com/en-us/windows/desktop/winsock/creating-a-basic-winsock-application

tried it out and it works now

@jweiA10 How did you get it working on Windows? Can you please share your steps? Thanks.

@fstojanovic
Copy link

fstojanovic commented Oct 6, 2020

If anybody is wondering, for Windows, the easiest method is to replace, in PracticalSocket.cpp :

#include <winsock.h>         // For socket(), connect(), send(), and recv()

by :

#ifdef WIN32
  #include <WinSock2.h>         // For socket(), connect(), send(), and recv()
  #include <Ws2tcpip.h>
  #pragma comment(lib, "Ws2_32.lib")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants