蓝色的香菇 2014-02-17 09:09 采纳率: 0%
浏览 2218

链接脚本中符号查找问题

文件1: test1.c
#include

int test1()
{
printf("test\r\n");
}

文件2:test2.c
#include

int test2()
{
test1();
}

文件3:test.c
#include

int main()
{
test2();
}

编译:
gcc -c test1.c
gcc -c test2.c
gcc -c test.c

ar r test1.a test1.o
ar r test2.a test2.o

gcc -o test test.o test1.a -Wl,-whole-archive test2.a -Wl,-no-whole-archive

编译时会报test1函数没有定义。而test1.a换成test1.o就没有问题,

请问各位大神,为啥会找到不到test1函数,链接命令不变的情况下怎么做才能找到test1函数呢?

  • 写回答

1条回答 默认 最新

  • 滴水冰冻 2014-02-17 10:39
    关注

    把函数的声明放到同一个.h文件里,然后引用该头文件。

    评论

报告相同问题?