c - 架构冲突?在 mac 上找不到体系结构 x86_64 的符号

标签 c gcc makefile architecture x86-64

我正在尝试安装 C 库:ssht

我已经设置了 makefile,它肯定能找到依赖项。然而,当我使用 gcc 实现时,我收到了一些警告:

In file included from ../ssht/src/c/ssht_core.c:23:0:
../ssht/src/c/ssht_core.c: At top level:
../ssht/src/c/ssht_sampling.h:39:20: warning: inline function ‘ssht_sampling_ind2elm’ declared but never defined
extern inline void ssht_sampling_ind2elm(int *el, int *m, int ind);

然后当我对代码进行测试时出现错误:

"_ssht_sampling_elm2ind", referenced from:
  _ssht_test_gen_flm_complex.constprop.1 in ssht_test.o
  _ssht_test_gen_flm_real in ssht_test.o
  _ssht_test_gen_lb_flm_real in ssht_test.o
  _ssht_test_gen_flm_complex in ssht_test.o
  _ssht_test_gen_lb_flm_complex in ssht_test.o
  _main in ssht_test.o
  _ssht_core_mwdirect_inverse in libssht.a(ssht_core.o)
  ...
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [../ssht/bin/c/ssht_test] Error 1

我一直没能找到任何我能理解的解决方案。顺便说一句,我的 gcc 版本是:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin14.4.0/5.1.0/lto-wrapper
Target: x86_64-apple-darwin14.4.0
Configured with: ../gcc-5.1.0/configure --enable-languages=c++,fortran
Thread model: posix
gcc version 5.1.0 (GCC)

我已经尝试使用 -m32 作为 32 位安装来安装以查看是否改变了一些东西,但是我在使用 i386 而不是 x86_64 时遇到了同样的错误。

我已经将它安装在一台 Linux 机器上,我也可以使用一个 makefile 访问它,除了其中一个依赖项的位置之外,该文件是相同的。

请帮忙!

最佳答案

看来代码已损坏,您提供的警告确实是一个很好的线索。该标准规定:

For a function with external linkage, the following restrictions apply: If a function is declared with an inline function specifier, then it shall also be defined in the same translation unit. If all of the file scope declarations for a function in a translation unit include the inline function specifier without extern, then the definition in that translation unit is an inline definition. An inline definition does not provide an external definition for the function [...].

[C2011, 6.7.4/7]

警告表示违反了引用的限制:警告中指示的头文件包含给定的函数声明,它带有 inlineextern 说明符。由于 inline 说明符,C 要求出现该声明的每个翻译单元也提供一个定义;因为它出现在头文件中,所以适用于包含该头文件的每个源文件。文件 ssht_core.c 包含 header 但不提供定义。

源代码检查显示指定函数仅在文件 ../ssht/src/c/ssht_sampling.c 中定义,但该文件不包含相应的 header 。当一个 C 源文件有一个相应的头文件时,包含该头文件通常是有用的,因为这有助于捕获声明之间的差异。然而,这样做并不是必须的,因此遗漏本身并没有错。

然而,在这种情况下,ssht_sampling.cssht_sampling_ind2elm() 的唯一声明是它的定义,并且带有 inline没有 extern 的说明符。因此,上述标准的第二部分适用:对应于该文件的翻译单元不提供函数的外部定义。也就是说,它提供的定义仅在同一翻译单元内可见,而在其他翻译单元中不可见,例如与 ssht_core.c 关联的单元。

意图似乎是在一个文件中提供一个可以内联到其他文件中的函数定义,但这是不允许的,也没有任何意义。我会向图书馆的作者提交错误报告。一种可能的解决方案是使 ssht_sampling.c 包含自己的 header ;那不会解决警告,但它应该解决链接问题。您可以通过从 header 中的函数声明中删除inline 说明符来清除警告。或者,您可以从 header 和主源中的函数中删除 inline 说明符,而不更改哪个 header 包含在哪个文件中。

关于c - 架构冲突?在 mac 上找不到体系结构 x86_64 的符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38483284/

相关文章:

c - Unix 源代码 - 找到我的出路

c++ - 将已编译的库和包含文件添加到 CMake 项目?

linux - 无法编译qc-usb驱动?

c - 如何使用 sscanf 获取名称并按照我想要的方式打印它们

c - readdir() 是否保证订单?

c - Eclipse CDT 中是否有配置类型的预定义宏?

recursion - 递归gmake问题

c - 如何将 C 结构体与 4 字节边界对齐?

c++ - 投影 makefile 以进行调试/发布配置

makefile - 如何导入 yaml 文件以在 gnu make 文件中使用它?