5

我编写了一个简单的客户端服务器程序,其中服务器接受来自客户端的消息并打印它们的详细信息(为我的作业硬编码)。我最初是在 Linux (Fedora) 机器上编写的,它运行得非常好。但是当我尝试在我的 mac 上编译服务器代码时,它不起作用。

这是编译后的消息:

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

谁能帮我解决这个问题?

4

3 回答 3

3

Put this at the top of your main file:

#ifdef __APPLE__
#  define error printf
#endif
于 2013-06-01T06:03:45.947 回答
1

来自“人 3 错误”:

   These functions and variables are GNU extensions,  and  should  not  be
   used in programs intended to be portable.

因此,请勿在需要在非 GNU 系统上运行的程序中使用此功能,或提供您自己的替代品。

于 2013-09-18T21:54:17.320 回答
0

您的error函数可能位于主文件之外的另一个文件中,您包含其声明但不包含其实现:

尝试像这样编译:

g++ main.c -l<filetolink>

filetolink 是包含error函数实现的文件的名称(不带扩展名)

参考:C - 在 Mac OSX Lion 上编译时架构 x86_64 的未定义符号 在谷歌搜索第一个错误行时似乎有多种解决方案来解决这个问题

于 2013-06-01T05:44:41.650 回答