Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

C++ Winsock problems

c++ winsock linker libraries

  • Please log in to reply
1 reply to this topic

#1 Dako300

Dako300

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts
  • Programming Language:C
  • Learning:C

Posted 23 September 2012 - 09:58 AM

I am having some trouble compiling a little program I found on the internet. it has no errors but it does have a lot of undefined references (about 20) to things. Here are the errors.:

Compiling: C:\Users\Daniel\Desktop\main.cpp
Linking console executable: bin\Release\Networking.exe
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x24): undefined reference to `_WSAStartup@8'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x50): undefined reference to `_WSACleanup@0'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x78): undefined reference to `_socket@12'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0xb3): undefined reference to `_WSACleanup@0'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0xd2): undefined reference to `_WSACleanup@0'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x10d): undefined reference to `_send@16'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x144): undefined reference to `_recv@16'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x168): undefined reference to `_closesocket@4'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x23c): undefined reference to `_listen@8'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x269): undefined reference to `_WSACleanup@0'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x293): undefined reference to `_accept@12'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x2bf): undefined reference to `_accept@12'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x2f3): undefined reference to `_inet_addr@4'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x309): undefined reference to `_htons@4'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x333): undefined reference to `_bind@12'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x360): undefined reference to `_WSACleanup@0'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x3b3): undefined reference to `_inet_addr@4'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x3c9): undefined reference to `_htons@4'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x3f3): undefined reference to `_connect@12'
obj\Release\C\Users\Daniel\Desktop\Socket.o:Socket.cpp:(.text+0x420): undefined reference to `_WSACleanup@0'

I think I am not giving the linker the correct -l statements. the linker settings are -mwindows and thats it.
  • 0

#2 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 23 September 2012 - 08:49 PM

Can you show the code here? The linking errors are because linker is not able to find the library/DLL for all those API the code used.

However, it seems you are trying with Visual Studio, right? If yes, you just need to properly apply linker settings to link to 'Ws2_32.lib'. To do that read the tutorial here -- go to section 'How to Link to 3'rd Party Libraries'
  • 0





Also tagged with one or more of these keywords: c++, winsock, linker, libraries

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download