Compile problems from Linux to OS X

Soldato
Joined
6 Dec 2002
Posts
3,400
Location
North East
I'm trying to do my networks assignment in C which was originally compiled with no problems at university on Red Hat Linux. It involves sockets so I need to include sys/sockets.h but everytime I compile in terminal I get errors :(

Although, I tried with XCode and when I build the files they build with no errors but it doesn't produce compiled files :confused: I must be doing something wrong, but not sure exactly what :(

Any ideas?

BeatMaster :D
 
No idea about XCode don't use it but can you compile with gcc and see what errors it gives?
 
Xcode uses gcc for doing its C/C++ obj C compilation, so it probably is compiling your code but putting the executables somewhere stupid by default.

Also if you have xcode installed on the Mac you should be able to use the standard gcc -olm foo foo.c commandline build arguments you use under Linux.
 
johns-computer:~/desktop/sockets john$ gcc client.c -o client
client.c: In function 'main':
client.c:49: warning: incompatible implicit declaration of built-in function 'strlen'
/usr/bin/ld: Undefined symbols:
_close_socket
_connect_sockets
_create_socket
_recv_data
_send_data
collect2: ld returned 1 exit status

:o

BeatMaster :D
 
Firstly include string.h to fix strlen warning, then try compile with,
gcc client.c -o client -lsocket
 
Una said:
Firstly include string.h to fix strlen warning, then try compile with,
gcc client.c -o client -lsocket

Almost...

johns-computer:~/desktop/sockets john$ gcc client.c -o client -lsocket
/usr/bin/ld: can't locate file for: -lsocket
collect2: ld returned 1 exit status

Cheers for help :)

BeatMaster :D
 
Weird it should be in /usr/include/sys/socket.h .. Can you check to see if it even exists? If it is in a weird location your gonna need to pass the path as a linker option. If its missing I guess you are lacking dev libraries... though I would have thought they would have got installed when you installed gcc/xcode.
 
Una said:
Weird it should be in /usr/include/sys/socket.h .. Can you check to see if it even exists? If it is in a weird location your gonna need to pass the path as a linker option. If its missing I guess you are lacking dev libraries... though I would have thought they would have got installed when you installed gcc/xcode.

Yep, socket.h exactly where you said :( Hmm...don't know what on earth is the problem :mad:

BeatMaster :D
 
Lets see the code.. (those symbols are not out of socket.h anyhow.. so I don't think thats the problem)
 
Last edited:
Solved! :) Was compiler issues with GCC Version 4. Installed 3.4 and now none of the errors coming up :) All credit to my girlfriend though, she was the one who suggested that it might be the compiler at fault.

Cheers for all the help the Una, still solve the strlen problem :)

Can get on with networks assignment now :(

BeatMaster :D
 
Back
Top Bottom