Thread: socket errors

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    227

    socket errors

    I am tring to run a socket programm on windows 9x and im using bloodshed but i keep getting an error everytime i try to run a program using socket( AF_INET, SOCK_STREAM, 0 )

    ERR: C:\WINDOWS\TEMP\ccB8edgb.o(.text+0x3c):1.c: undefined reference to `socket@12'

    Does anyone know why i keep getting this err?
    Only the strong survives.

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Are you linking to the appropriate libraries?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    errr linking.. i didnt know i hade to link any files... what files do i have to link.. in bloodshed to make this work, I know in linux.. there is no linking in volve
    Only the strong survives.

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    You can only do it in a project. Goto Project Options, then Parameters, click on "Add library and object", add "libwsock32.a"

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    hmm damn ok i did what ya told me to do .. and now i get

    g++: C:\Dev-C++\Lib\libwsock32: No such file or directory
    g++: file path prefix `C:\DEV-C_~1\BIN\' never used
    Only the strong survives.

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    nm i got it
    Only the strong survives.

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    blah.. check it .. i ran a sample code in my project and i keep getting the perror ( what am i doing wrong here )

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    #include <sys/types.h>
    #include <winsock.h>
    #include <errno.h>
    
    int main(int argc, char *argv[])
    {
       struct sockaddr_in socketz;    /* Structure of socket */
       int s_sock;                    /* Socket status */
    
    
       if(( s_sock = socket( AF_INET, SOCK_STREAM, 0 )) == -1 )
       {
         perror( "Error" );
         exit( 1 );
       }
    
       printf( "Socket status: ON!\n" );
       return 0;
    }
    Only the strong survives.

  8. #8
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    to program in windows sockets, you need to run WSAStartup and WSACleanup, not exactly sure how they work, I use linux, but those functions tell which version of winsock to use so you don't get those undefined errors, probably fixing the perror thing also. try searching here for more on WSAStartup and all
    http://msdn.microsoft.com
    or go to google and search beej, and feel lucky.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  9. #9
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    1) You don't need that many header files to run the code you gave
    2) Expand your code to find out what the error is.
    3) chrismiceli is right about WSAStartup() being need

  10. #10
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    Ya thanx.. btw... the header files are added.. cause i will be adding more to that code.. =) thanx again
    Only the strong survives.

  11. #11
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    the header files are added.. cause i will be adding more to that code
    But if you are getting errors it helps to eliminate all unneeded stuffs. Then go back in and add as you need, that way if you start getting errors again it is easier to figure out what is causing it.

  12. #12
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    ya that is true.. thanx again all
    Only the strong survives.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Socket class OOD
    By lord mazdak in forum C++ Programming
    Replies: 6
    Last Post: 12-17-2005, 01:11 AM
  3. Socket Help - Multiple Clients
    By project95talon in forum C Programming
    Replies: 5
    Last Post: 11-17-2005, 02:51 AM
  4. Socket code problems
    By Phan in forum Networking/Device Communication
    Replies: 10
    Last Post: 09-14-2005, 04:23 PM
  5. socket programming in linux
    By crazeinc in forum C Programming
    Replies: 1
    Last Post: 05-27-2005, 07:40 PM