user2442462
user2442462

Reputation: 67

client server program in C

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

Answers (3)

crosser
crosser

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

perreal
perreal

Reputation: 97938

Put this at the top of your main file:

#ifdef __APPLE__
#  define error printf
#endif

Upvotes: 3

Antoine
Antoine

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

Related Questions