Thread: Fatal error with solaris socket

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    164

    Fatal error with solaris socket

    Hi, I ran into some issues when compiling my program on a sun solaris box.

    I am using the header <sys/socket.h> and when I compile I get the error message:
    Code:
    Undefined                       first referenced
     symbol                             in file
    inet_addr                           /var/tmp//ccjs1p18.o
    connect                             /var/tmp//ccjs1p18.o
    socket                              /var/tmp//ccjs1p18.o
    sendfile                            /var/tmp//ccjs1p18.o
    ld: fatal: Symbol referencing errors. No output written to utilserv
    collect2: ld returned 1 exit status
    in the beej online manual I noticed a warning about linked libraries for sun solaris users. does anyone know if this is related? If so, can anyone point in the direction of a possible fix?

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    those are all socket calls. you need to link to libsocket.a, libsocket.so or something
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    164
    Thanks for the reply, I am new to unix programing using gcc, can I just add the link to my header file or do I have to do it somewhere else? In windows I would just link it using tools built into the compiler. Not sure how to do this in unix. Thanks for any help-

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    oh ok. you're compiling from the command line using something like:

    gcc soandso.cpp

    I assume?

    if so, try:

    gcc -c soandso.cpp

    as a compile-only step, then....

    gcc -o soandso soandso.o -L/path/to/socket/lib -lsocket

    -o is the output name for these things that will be linked into it.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    additionally, you should probably use a makefile or at the very least a script file to execute those instructions without having to retype them
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  6. #6
    Registered User
    Join Date
    May 2004
    Posts
    164
    ok, I will look up the path for the link libraries and try that call for my compile. Thanks-

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Moved from the C# forum
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    May 2004
    Posts
    164
    ya that seems like alot of work, do I need to do that for just the .c file I am trying to compile? meaning

    gcc -o utillcc utilserv.c ect.....

  9. #9
    Registered User
    Join Date
    May 2004
    Posts
    164
    Hi salem, I am actually writing in c, so thats why I posted here, But I have strange compiler not really using gcc but a c compiler on the solaris box. I am just trying to follow a reference from fillyourbrain. Sorry if I appeared to be posting a c++ in the c, I am using c for the language though.

  10. #10
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    the -c flag (for gcc anyway) is "compile only". That means that you can do it to the c file to produce a .o file. the final step is linking. That's where you have to include everything that needs to go into the final binary. This must include the -L and -l flags which are the link path and library name respectively. I always do them as two steps but I'm pretty sure you can do them as one.

    as for salem's move, your question does have more to do with C compilers than it does linux, but then if it was moved from the C# (I think that's where it was) then the move was half way right
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  11. #11
    Registered User
    Join Date
    May 2004
    Posts
    164
    cool, thanks for all the info, I am working on that now. I'll post a success or fail. I appreciate your time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. socket programming question, closing sockets...
    By ursula in forum Networking/Device Communication
    Replies: 2
    Last Post: 05-31-2009, 05:17 PM
  2. when to close a socket
    By Wisefool in forum Networking/Device Communication
    Replies: 5
    Last Post: 11-02-2003, 10:33 AM
  3. problem closing socket
    By Wisefool in forum Networking/Device Communication
    Replies: 2
    Last Post: 10-29-2003, 12:19 PM
  4. problem closing a socket
    By Wisefool in forum C Programming
    Replies: 1
    Last Post: 10-28-2003, 01:38 PM
  5. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM