Apple Mach-O 链接器错误,由于文件扩展名
可怕的典型链接器错误..
ld: 找不到架构 armv6 的符号 collect2: ld returned 1 exit status
但是,这是由文件名引起的?我使用 C++/Objective-C,所以我所有的 Obj-C 文件都是 .mm,但我永远不能使用任何 .c 文件。例如,我在我的项目中包含了 SFMT 算法,这给了我这些错误,但只需将单个 .c 文件更改为 .cpp 就可以让它消失,并且代码工作得很好!我只包含标题,所以我不确定为什么这会产生任何影响。
现在的问题是我试图包含 Freetype2,给了我同样的问题(很确定这是因为它是 .c),但这太大了,无法重命名每个文件,而且我还使用链接的二进制文件,所以除非我用新文件名重新编译它,我无法更改它。所以现在是时候找出这背后的真正原因了。
知道为什么会发生这种情况吗?如何阻止 .c 文件的链接器错误?
The dreaded typical linker error..
ld: symbol(s) not found for architecture armv6
collect2: ld returned 1 exit status
However, it is caused by filename? I use C++/Objective-C, so all of my Obj-C files are .mm, but I can never use any .c files. For example I've included the SFMT algorithm in my project, which was giving me these errors, but just changing the single .c file to .cpp made it go away and the code works just fine! I am only including the headers, so I'm not sure why this makes any difference.
The problem now is I'm trying to include Freetype2, giving me the same issue (pretty sure it's because it's .c), but that is far too large to rename every file, and I'm also using a linked binary, so unless I recompile it with new filenames, I can't change that. So now it's time to find the real reason behind this.
Any idea why this would happen? How can I stop linker errors for .c files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 Freetype 包含在
extern "C"
指令中:您可以在
extern " 中使用
指令。我从未尝试过,但我不明白为什么它不起作用。#import
而不是#include
C"Wrap your Freetype includes within an
extern "C"
directive:You can probably use
#import
instead of#include
within anextern "C"
directive. I've never tried, but I don't see why it wouldn't work.用这个包围你的 c 头文件。这也可以包含:
这指定了 c 函数的外部链接。
如果在包含 c .h 文件时不这样做,C++ 编译器将以与 C 编译器不同的方式进行破坏,并导致链接器出现问题。
通过使用
extern "C"
,您可以告诉 C++ 编译器使用 C 风格的函数重整。Surround your c header file with this. This can also surround the include:
This specifies external linkage for your c functions.
If you don't do this when you include your c .h files the C++ compiler will mangle in a different way from the C compiler, and cause problems for the linker.
By using
extern "C"
, you are telling your C++ compiler to use C-style mangling of the functions.