簡単な問題:
次のプログラムが与えられた場合:
#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
はないと思います:
Linker error inline function (これは別のオブジェクトにあり、ゼロではなく2つの定義を扱っているため)
これは関連リンクですが、これは C++ であり、標準 C でヘッダーにコードを配置するのは良い習慣ではないと思います:
インライン関数リンカー エラー
コンパイラ情報:
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