首页 文章

C中的客户端服务器程序

提问于
浏览
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

任何人都可以帮我解决这个问题吗?

3 回答

  • 0

    把它放在主文件的顶部:

    #ifdef __APPLE__
    #  define error printf
    #endif
    
  • 1

    从“男人3错误”:

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

    因此,不要在需要在非GNU系统上工作的程序中使用此函数,或者提供自己的替换 .

  • 3

    你的 error 函数可能在主文件之外的另一个文件中,你包括它的声明但不包括它的实现:

    尝试像这样编译:

    g++ main.c -l<filetolink>
    

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

    参考:C - Undefined symbols for architecture x86_64 when compiling on Mac OSX Lion在谷歌搜索第一个错误行时似乎有多个解决方案

相关问题