chenxiaoqino / udp-image-streaming

Compress and stream live images over UDP protocol with OpenCV
214 stars 103 forks source link

LNK2019 when build in Visual Studio 2017 #10

Open kxu-ffd opened 6 years ago

kxu-ffd commented 6 years ago

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 commented 6 years ago

I never tried to build under Windows. Perhaps you need to update the socket API to use Windows WinSock, a totally different system. (Unix-based systems uses the same API for network sockets.)

-- Yours sincerely, Xiaoqi Chen cxqn.info

On Sat, Jul 28, 2018 at 4:00 PM, kxu-ffd notifications@github.com wrote:

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 https://github.com/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 https://github.com/v?$ allocator@D@2@@std https://github.com/std@@g https://github.com/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 https://github.com/v?$allocator@D@2@@std https://github.com/std@@xz https://github.com/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 https://github.com/v?$ allocator@D@2@@std https://github.com/std@@xz https://github.com/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 https://github.com/v?$ allocator@D@2@@std https://github.com/std@@@z https://github.com/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 https://github.com/v?$ allocator@D@2@@std https://github.com/std@@xz https://github.com/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 https://github.com/v?$allocator@D@2@@std https://github.com/std@@aeag https://github.com/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 https://github.com/v?$allocator@D@2@@std https://github.com/std@@g https://github.com/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 https://github.com/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 sockaddrin &)" (?fillAddr@@YAXAEBV?$basic string@DU?$char_traits@D@std@@v https://github.com/v?$allocator@D@2@@std https://github.com/std@@GAEAUsockaddr_in@@@z https://github.com/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 https://github.com/v?$allocator@D@2@@std https://github.com/std@@0 https://github.com/0@Z) 2>PracticalSocket.obj : error LNK2019: unresolved external symbol WSAStartup referenced in function "protected: cdecl Socket::Socket(int,int)" (??0Socket@@iEAA https://github.com/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)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/chenxiaoqino/udp-image-streaming/issues/10, or mute the thread https://github.com/notifications/unsubscribe-auth/ABvpXhWqS3Vp0ojWlC8XAJiaGt_WoXxRks5uLMLNgaJpZM4VlKkC .

email2jie commented 6 years ago

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

chenxiaoqino commented 6 years ago

Oh interesting, then I dont know why there's linking error. Probably we need to add a flag (similar to the gcc -lm flag for math module)?

On Mon, Jul 30, 2018, 15:35 Jie Wei notifications@github.com wrote:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/chenxiaoqino/udp-image-streaming/issues/10#issuecomment-408983713, or mute the thread https://github.com/notifications/unsubscribe-auth/ABvpXjroxVfCnjMZM5_MtxNvu_-de36sks5uL1_tgaJpZM4VlKkC .

email2jie commented 6 years ago

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 commented 6 years ago

I dont believe its an issue related to x64 in general, as I wrote those code under OS X x64. I vaguely remember I also tested under VS 2013 x64.

On Mon, Jul 30, 2018, 16:39 Jie Wei notifications@github.com wrote:

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?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/chenxiaoqino/udp-image-streaming/issues/10#issuecomment-409002161, or mute the thread https://github.com/notifications/unsubscribe-auth/ABvpXiRRxpvYu1uM7FjNd-HkDOwLZQhhks5uL27ngaJpZM4VlKkC .

email2jie commented 6 years ago

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 commented 5 years ago

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

BrieoRobino commented 5 years ago

Any plans on updating this to build in windows?

chenxiaoqino commented 5 years ago

These code was originally build on Windows using VS2015. If something is broken now on VS2019, feel free to open pull requests.

AlexYiningLiu commented 4 years ago

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 commented 4 years ago

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")