未定义的建筑符号 x86_64 : Cadventure-txt

Undefined symbols for architecture x86_64 : Cadventure-txt

我正在尝试让 Cadventure-txt 进行编译,但我一直收到 Undefined symbols for architecture x86_64 错误。我阅读了 SO 以找到可能的解决方案,但到目前为止,无济于事。

我没有更改 github 上可用的文件。如果有人能理解以下错误,那就太好了:)我对 C 和编程还很陌生,所以我不知道从哪里开始调试这样的错误。

这是完整的错误:

Undefined symbols for architecture x86_64:
  "_is_command", referenced from:
      _init in main.o
      _play in main.o
  "_is_letter", referenced from:
      _init in main.o
      _play in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

ld 开头的错误行来自链接器 ld

它说找不到您使用的符号(即函数名);可能,您只是没有链接到包含这些函数的文件。

_is_command_is_letter两个函数定义为inline.

你说你正在使用 XCode 作为编译器,它使用 Clang。

默认情况下,Clang 在 GNU C11 模式下构建 C 代码,因此它对 inline 关键字使用标准 C99 语义。在C99中,内联是指一个函数的定义只是为了内联而提供的,而在程序的其他地方还有另一个定义(没有内联)。

但是程序中没有对这些函数的其他定义,所以在link时出现未定义符号的错误。

一些解决方案:

  • 将函数定义为 static inline
  • 删除 inline.
  • 为函数添加非内联定义。
  • 使用 std=gnu89 在 GNU C89 模式下编译。

阅读更多相关信息 here