newbie question - winsock compile error

Discussion in 'C Programming' started by Jay, Aug 8, 2003.

  1. Jay

    Jay Guest

    I am getting following error when trying to compile a sample program:

    C:\DOCUME~1\user1\LOCALS~1\Temp\cckJbaaa.o(.text+0x38):test27.cpp:
    undefined reference to `WSAStartup@8'
    C:\DOCUME~1\user1\LOCALS~1\Temp\cckJbaaa.o(.text+0x71):test27.cpp:
    undefined reference to `WSACleanup@0'

    Here is my code:

    // c program
    #include <stdio.h>
    #include <io.h>
    #include <winsock.h>

    int main()
    {
    WORD wVersionRequested = MAKEWORD(1,1);
    WSADATA wsaData;
    int nRet;

    // Initialize WinSock.dll
    nRet = WSAStartup(wVersionRequested, &wsaData);
    if (nRet)
    {
    fprintf(stderr,"\nWSAStartup(): %d\n", nRet);
    WSACleanup();
    return 1;
    }
    return 0;
    }

    // END

    How can I fix it?

    Thanks in advance for any help.
    Jay, Aug 8, 2003
    #1
    1. Advertising

  2. Jay wrote:

    > I am getting following error when trying to compile a sample program:
    >
    > C:\DOCUME~1\user1\LOCALS~1\Temp\cckJbaaa.o(.text+0x38):test27.cpp:
    > undefined reference to `WSAStartup@8'
    > C:\DOCUME~1\user1\LOCALS~1\Temp\cckJbaaa.o(.text+0x71):test27.cpp:
    > undefined reference to `WSACleanup@0'


    Link ws2_32.lib into your program.

    Regards,
    Markus
    Markus Cserna, Aug 8, 2003
    #2
    1. Advertising

  3. Jay

    bd Guest

    On Fri, 08 Aug 2003 05:56:56 -0700, Jay wrote:

    > I am getting following error when trying to compile a sample program:
    >
    > C:\DOCUME~1\user1\LOCALS~1\Temp\cckJbaaa.o(.text+0x38):test27.cpp:
    > undefined reference to `WSAStartup@8'
    > C:\DOCUME~1\user1\LOCALS~1\Temp\cckJbaaa.o(.text+0x71):test27.cpp:
    > undefined reference to `WSACleanup@0'


    Winsock is not defined in the ISO C standard, and is thus off-topic in
    comp.lang.c. Try comp.os.ms-windows.programmer.tools.winsock or some other
    group with 'winsock' in the name.
    bd, Aug 8, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Thompson

    server using winsock

    Chris Thompson, Sep 2, 2003, in forum: C++
    Replies:
    1
    Views:
    427
    Jim Fischer
    Sep 2, 2003
  2. Abbas Akhtar

    winsock api for newbies

    Abbas Akhtar, Sep 16, 2003, in forum: C++
    Replies:
    2
    Views:
    449
    Peter van Merkerk
    Sep 16, 2003
  3. Dom
    Replies:
    1
    Views:
    12,587
  4. Nagaraj
    Replies:
    1
    Views:
    842
    Lionel B
    Mar 1, 2007
  5. Moe
    Replies:
    2
    Views:
    417
    Rich Webb
    Nov 13, 2011
Loading...

Share This Page