Reputation: 67
I have written a simple client server program in which server accepts messages from clients and prints their details (hard coded for my assignment). I had written this at first on a Linux (Fedora) machine, and it was working perfectly fine. But when I try to compile the server code on my mac, it doesn't work.
Here is the message after compilation:
Undefined symbols for architecture x86_64:
"_error", referenced from:
_main in cc3O1167.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Can anyone help me out with this?
Upvotes: 5
Views: 1058
Reputation: 727
From "man 3 error":
These functions and variables are GNU extensions, and should not be
used in programs intended to be portable.
So, do not use this function in programs that need to work on non-GNU systems, or provide your own replacement.
Upvotes: 1
Reputation: 97938
Put this at the top of your main file:
#ifdef __APPLE__
# define error printf
#endif
Upvotes: 3
Reputation: 2807
Your error
function is probably in another file than the main file, you are including its declaration but not its implementation:
Try to compile like this:
g++ main.c -l<filetolink>
filetolink being the name of the file containing the implementation of the error
function (without the extension)
Reference: C - Undefined symbols for architecture x86_64 when compiling on Mac OSX Lion Seems to have multiple solutions to this problem when googling the first error line
Upvotes: 0