メインプログラムがあります:
#include <stdio.h>
extern int a;
int main (int argc, char ** argv) {
int i;
printf ("Hello %p, %p\n", & i, & a);
return 0;
}
foo.c
変数 の私の定義を含む別のファイルa
:
int a;
私がこのように構築した場合:
clang -c main.c foo.c
clang main.o foo.o
./a.out
すべては順調です。しかし、私が次のことをすると:
ar rvs bar.a foo.o
わからないという警告が出ます
r - foo.o
warning: /<elided>/ranlib:
warning for library: bar.a the table of contents is empty
(no object file members in the library define global symbols)
ライブラリをチェックして、シンボルがそこにあることを確認します
nm bar.a
bar.a(foo.o):
0000000000000004 C _a
そして、私はします
clang main.o bar.a
次のエラーが表示されます
Undefined symbols for architecture x86_64:
"_a", referenced from:
_main in main-5121f1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
私は何を取りこぼしたか?