【问题标题】:Why does clang create a linking problem when the symbols are present?当符号存在时,为什么clang会产生链接问题?
【发布时间】:2018-10-21 21:12:43
【问题描述】:

我有一个奇怪的链接问题。我有一堆要编译的文件,但是遇到了未定义的符号错误。以下是错误:

clang U_outsup.o U_OUTSUR.o
Undefined symbols for architecture x86_64:
  "U_outsup(surface*, __sFILE*)", referenced from:
      U_outsur(surface*, char*) in U_OUTSUR.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

当我尝试将源文件编译为输出可执行文件时,也会发生同样的情况。如果我查看这些目标文件 (clang -c U_outsup.c U_OUTSUR.C),我会看到以下内容:

U_outsup.o:     file format Mach-O 64-bit x86-64

SYMBOL TABLE:
0000000000000420 l       __DATA,__data  _rname
0000000000000000 g     F __TEXT,__text  _U_outsup
0000000000000000         *UND*  _A_extcpc
0000000000000000         *UND*  _E_seterr
0000000000000000         *UND*  _U_issurr
0000000000000000         *UND*  _U_surbre
0000000000000000         *UND*  _fprintf

U_OUTSUR.o:     file format Mach-O 64-bit x86-64

SYMBOL TABLE:
0000000000000090 l       __DATA,__data  __ZL5rname
0000000000000000 g     F __TEXT,__text  __Z8U_outsurP7surfacePc
0000000000000000         *UND*  __Z8E_seterrlPc
0000000000000000         *UND*  __Z8U_outsupP7surfaceP7__sFILE
0000000000000000         *UND*  _fclose
0000000000000000         *UND*  _fopen

所以,我假设找不到符号“U_outsup(surface*, __sFILE*)”,因为它在符号表中有一个荒谬的名称。谁能帮我弄清楚这里发生了什么?再次感谢。

【问题讨论】:

    标签: c gcc compilation clang ld


    【解决方案1】:

    它没有一个荒谬的名字。它有一个 c++ 重命名的名称。

    这意味着它是用 c++ 编译器而不是 c 编译器构建的。使用 gcc 或 clang,而不是 g++ 或 clang++ 重新编译库。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-02
      • 2013-04-27
      • 2022-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-25
      • 2012-05-08
      相关资源
      最近更新 更多