Thread: winsock linking problems

  1. #1
    Registered User
    Join Date
    Dec 2005
    german border

    winsock linking problems


    I am trying to get my head around windows sockets, however they are proving to be a lot more complex than in linux. So I decided to see just how much I would need to modify a simple echo client for linux to work in windows. I am using dev-c++ and I have changed all the parts of the program which I need to as far as I know. However, I still get errors about linking:

      [Linker error] undefined reference to `socket@12' 
      [Linker error] undefined reference to `htons@4' 
      [Linker error] undefined reference to `inet_addr@4' 
      [Linker error] undefined reference to `connect@12' 
      [Linker error] undefined reference to `send@16' 
      [Linker error] undefined reference to `recv@16' 
      ld returned 1 exit status
    Now, I realised that my problem is probably me not linking the winsock library when compiler. So added "wsock32.lib" without quotes to tools->compiler options->compiler tab in the "Add these commands to the linker command line" box. The program compiles but fails to save the compiled copy, there are no compiler errors. It just claims the source file has not been compiled, and it is nowhere to be found in the specified folder. I'm pretty stumped, I thought that I might have forgot a command line switch in the linker box, but then it wouldn't work at all and I would still get the linker errors right?

    Thanks in advance,


  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Add "-lws2_32" (of course without quotes), not wsock32.lib if you have Dev-C++...
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Add the winsock library to the link list. I dont have GCC handy at the moment, so im nto usre exactly where, but there is a spot to put in which files you want to add. Although under gcc I think the use the extension .A

    Not linking the winsock library is definately the problem.
    Last edited by abachler; 08-29-2007 at 08:57 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linking problems
    By chris285 in forum C++ Programming
    Replies: 6
    Last Post: 01-09-2005, 01:39 AM
  2. Winsock Safety in C
    By sean in forum C Programming
    Replies: 1
    Last Post: 11-24-2004, 10:15 AM
  3. Huge problems in Winsock recv!
    By sirSolarius in forum Networking/Device Communication
    Replies: 0
    Last Post: 09-11-2004, 09:34 AM
  4. Linking problems
    By MMD_Lynx in forum C++ Programming
    Replies: 12
    Last Post: 08-10-2004, 10:32 AM
  5. Im having linking problems with turbo c++ ver 4.5
    By Marcos in forum C++ Programming
    Replies: 4
    Last Post: 05-17-2004, 04:57 PM