简单的问题:
给定以下程序:
#include <stdio.h>
inline void addEmUp(int a, int b, int * result)
{
if (result) {
*result = a+b;
}
}
int main(int argc, const char * argv[])
{
int i;
addEmUp(1, 2, &i);
return 0;
}
我收到链接器错误...
Undefined symbols for architecture x86_64:
_addEmUp", referenced from:
_main 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)
似乎它不需要编译它。
它不应该是static
,我不认为,根据我读过的内容:
链接器错误内联函数(因为这是在不同的对象中,并且处理2个定义而不是零)
这是一个相关链接,但它是 c++,我认为在标准 C 中将代码放在标题中不是一个好习惯:
inline function linker error
编译器信息:
cc --version
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.3.0
Thread model: posix
编译示例:
# cc main.c
Undefined symbols for architecture x86_64:
"_addEmUp", referenced from:
_main in main-sq3kr4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocatio