【发布时间】:2011-03-10 01:58:54
【问题描述】:
我使用 gcc 制作了共享库。我想使用 g++ 编译器将这个库与源代码 *.c 链接起来。 示例
test_init.c
#include<stdio.h>
int test_init()
{
printf(" test init success\n");
return 0;
}
gcc -shared -o libtest.so test_init.c
test.c
#include<stdio.h>
extern int test_init();
main()
{
test_init();
}
g++ -I. -L. -ltest test.c
/tmp/ccuH5tIO.o:在函数
main': test.c:(.text+0x7): undefined reference totest_init()'collect2: ld 返回 1 个退出状态
注意:如果我用 gcc 编译 test.c 它可以工作,但由于其他依赖关系,我想使用这种方法。可以吗??
【问题讨论】: