テスト.c:
#include <stdio.h>
int main(){
return printf("helloworld %d",a);
}
ライブラリ.c:
int a=0;
test.c
a
の変数を使用しますlib.c
。共有図書館にしましたlib.so
。
gcc testbench.c -o test -l lib.so
エラー発生:
‘a’ undeclared (first use in this function)
で宣言されたので、予期しない結果ですlib.c
。
ベストアンサー1
a
ソースファイルと通信するには、外部に存在するコンパイラが必要です。これを行うには、次のように宣言してくださいextern
。
#include <stdio.h>
extern int a;
int main(void)
{
printf("helloworld %d", a);
return 0;
}