WinSocket Error Help

This is a discussion on WinSocket Error Help within the C Programming forums, part of the General Programming Boards category; I get this error when i compile the code to start a winsocket program 'In fucntion 'WinSocketStart': 'Linker Error, unidentified ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    10

    Exclamation WinSocket Error Help

    I get this error when i compile the code to start a winsocket program
    'In fucntion 'WinSocketStart':
    'Linker Error, unidentified reference to WSAStartup@8'
    id returned 1 exit status

    i think it means i don't have a library linked. but for winsock 2.0 i don't know how to link it with Dev-C++ any help would be great.

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <winsock2.h>
    
    void WinSockStart(void);
             
    int main(void)
    {
        WinSockStart();
        
        getchar();
        return 0;
    }
    
    
    void WinSockStart(void)
    {
         //all this is required for any socket programming app
             WSADATA wsaData;
             
             if (WSAStartup(MAKEWORD(2,0), &wsaData) !=0) {
                fprintf(stderr, "WSAStartup Failed.\n");
                exit(1);
                }
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If you look up the WSAStartup page on MSDN, it will tell you what library you need: Ws2_32.dll. You add that library in the big box labeled "libaries" in your compiler options. (You usually don't put the .dll part.)

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    You are going to need to link with ws2_32.lib (normal windows). You do this by adding the library via Input\Additional Dependencies field on the Linker tab/folder of the project Properties.
    Last edited by AndrewHunter; 08-20-2011 at 09:00 PM. Reason: Fixed lib name :(
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  4. #4
    Registered User
    Join Date
    Aug 2011
    Posts
    10
    with Dev-C++ i only get to pick a Dir not a file. and im not sure were the file is

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    A small modification will get you more details and give you a cleaner exit.

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <winsock2.h>
    
    void WinSockStart(void);
             
    int main(void)
    {
        if(!WinSockStart())
          exit(1);
        
        getchar();
        return 0;
    }
    
    
    BOOL WinSockStart(void)
    {
         //all this is required for any socket programming app
             WSADATA wsaData;
             
             if (WSAStartup(MAKEWORD(2,0), &wsaData)) {
                fprintf(stderr, "WSAStartup Failed with error code %d.\n", WSAGetLastError());
                return FALSE;
                }
         return TRUE;
    }
    WSAGetLastError function (Windows)

    Windows Sockets Error Codes (Windows)
    Last edited by CommonTater; 08-20-2011 at 09:04 PM.

  6. #6
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    If you downloaded the SDK, it should be somewhere in the folders it installed. You could always try to find it with windows explorer.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  7. #7
    Registered User
    Join Date
    Aug 2011
    Posts
    10
    i wasn't able to find it at all. is there a place you can manually donwload it and just stick it inside C:\Dev-CPP\lib ?

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by blackhat11907 View Post
    with Dev-C++ i only get to pick a Dir not a file. and im not sure were the file is
    Look at your linker options... there will be a list of .lib and/or .dll files there someplace... ws2_32.lib should be added...

    i wasn't able to find it at all. is there a place you can manually donwload it and just stick it inside C:\Dev-CPP\lib ?
    It should be in your windows lib directory... If it's not there, you may actually have a version of the compiler that precedes Winsock2 .... Run a Windows for ws*.lib search starting at the installation folder for your compiler, if it's in there that will find it. You'll get lots of hits but it will be on the list if it's there, as will the previous 1.0 version wsock32.lib.

    (Aside:This is one of those nifty things I like about Pelles C... there's a #define WIN32_DEFAULT_LIBS ... when you load a header it automatically includes the correct lib files... and yes it has full winsock support.)
    Last edited by CommonTater; 08-20-2011 at 09:16 PM.

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by blackhat11907 View Post
    with Dev-C++ i only get to pick a Dir not a file. and im not sure were the file is
    If that's what you see, you are not looking anywhere near the proper place to put a library.

  10. #10
    Registered User
    Join Date
    Aug 2011
    Posts
    10
    im under compiler options and under that theres libraries and it only lets me pick a dir

  11. #11
    Registered User
    Join Date
    Aug 2011
    Posts
    10
    ok i fixed it by manually adding it to the linker commands but now when i run the program it compiles it with no errors but when i run it it says that source file not compiled ?

  12. #12
    Registered User
    Join Date
    Aug 2011
    Posts
    10
    ok false alarm it didnt fix it. :/ wow this is very irritating

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I'll quote upstream, since I no longer have Dev-C++ installed and can't check:
    Quote Originally Posted by AndrewHunter View Post
    You do this by adding the library via Input\Additional Dependencies field on the Linker tab/folder of the project Properties.
    If you don't have a project set up, there was a place you could add libraries that were always added. You might be in the right place, perhaps; does the top say "library search path" or just "link libraries"? If the latter, you're just supposed to type the library names in the box.

    EDIT: Just for you, I have put Dev back on this box. The box is even easier than I remembered; right on the front page of options, "Add the following commands when calling compiler" you need "-lws2_32" without the quotes. The box you are looking at has "Directories" highlighted on the top, which is why it's only letting you specify a directory.
    Last edited by tabstop; 08-20-2011 at 09:22 PM.

  14. #14
    Registered User
    Join Date
    Aug 2011
    Posts
    10
    i go under tools->compiler options then under that thers a tap with Directory's and under that tab there i binary's, Libraries, C includes and C++ includes. they all make me pick Dir's instead of a file

  15. #15
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by blackhat11907 View Post
    i go under tools->compiler options then under that thers a tap with Directory's and under that tab there i binary's, Libraries, C includes and C++ includes. they all make me pick Dir's instead of a file
    Do you have a spot for linker options?

    But I should think you would first want to confirm that ws2_32.lib and ws2_32.dll actually exist on your setup.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 07-24-2011, 09:38 PM
  2. Replies: 1
    Last Post: 11-15-2010, 10:14 AM
  3. Replies: 3
    Last Post: 10-02-2007, 09:12 PM
  4. winsocket books
    By datainjector in forum Windows Programming
    Replies: 2
    Last Post: 11-01-2002, 11:06 AM
  5. error on winsocket
    By lliero in forum Windows Programming
    Replies: 2
    Last Post: 03-24-2002, 09:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21