Results 1 to 7 of 7

Thread: help with C compilation

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Posts
    161

    help with C compilation

    Hi all,
    I have a makefile with: -lsocket -lnsl at the end of a line(i will post the full makefile later).
    I have no clue what those do. The program compiled and ran succesfully under Solaris but when I tried in Mac OSx I get an error saying that I dont have the files for lscoket or lnsl. I removed those statements and it compiled but did not run properly.

    Any help would be appreciated.
    cheers,

    J

  2. #2
    Custom User
    Join Date
    Oct 2001
    Posts
    503
    As far as I am aware, "-l" includes a library, so what you posted would include the socket and nsl libraries. Are you using the same compiler on osx? Because it could be that it doesn't have those libraries, or that you need different source because the code you have is not totally portable.

    ac

  3. #3
    Banned
    Join Date
    Apr 2004
    Posts
    93
    what i think is the libraries used by the program for execution aren't there in Mac because there are some files which are present in Solaris but aren't compatible with Mac but if u use Mac os10 the program may work. the program on't work by deleting -I... statements because the program might not be able execute without those, what u can do to clarify the requirement of these statements is try to run the program without the statements in solaris!
    if the program don't work, then u can't delete these statements else the the these aren't important. happy programming..:->

  4. #4
    Senior Member
    Join Date
    Jan 2002
    Posts
    1,207
    The exact -l settings required vary slightly between different Unix-like systems.

    Linux requires neither -lsocket or -lnsl to compile most sockets programs. I suspect MacOS does not either. In this case the socket and nsl libraries are built in to the C library which is linked by default.

    Try it without them.

    Slarty

  5. #5
    Senior Member
    Join Date
    Apr 2002
    Posts
    161
    hey all, under MacOSX, if I remove the -lsocket and -lnsl the program compiles but when I run it it doesn't work properly. Those lines are required for compilation under Solaris, and the program works perfectly there.
    Any further help will be appreciated.

    cheers,
    J

  6. #6
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,401
    It would help knowing what "it doesn't run properly" means. Does it crash? Does it give you the wrong results? It doesn't do what's expected? What is expected?
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  7. #7
    Senior Member
    Join Date
    Apr 2002
    Posts
    161
    Ok, here goes the full explanation. I wrote a networking program in C that transfers a file using UDP. The file is split into packets and sent. I did it as an assignment at university. It compiled and ran perfectly on the Solaris machines at my school. I am just trying to port it and make it work on my Powerbook running MacOSX. I have not altered the code functionality in any way. I modified the makefile deleting the -lsocket -lnsl line then it compiled on the Mac.
    I ran the program on the Mac the same way I did at school just testing to transfer the file in localhost. Problem is it doesn't send anything it doesn't crash or give any seg faults. It just sends packet 0 over and over without receiving at the other end. It is very weird because the code was fine and it worked and sent any file under Solaris. I did not change any lines of code and it doesn't seem to work on the Mac. I assumed that removing the -lsocket -lnsl line on the makefile has some influence over program functionality.
    (BTW I got a 9.2/10 for that assignment)

    Is it an issue with my version of gcc? or maybe MacOSX is not as much unix as it claims to be?

    cheers,
    J

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •