[编程技术] 能忽略undefined reference to symbol 错误吗

发信人: zylthinking (ddd), 信区: Programming
标 题: 能忽略undefined reference to symbol 错误吗
发信站: 水木社区 (Thu Jun 29 15:55:39 2017), 站内

比如下面这种, 虽然 hell() 没有定义, 但实际上我也没调用 test2, 有没有办法强制链接成功, 而不是报告错误?

zylthinking@linux:~/downloads$ cat a.c

#include <stdio.h>

void test()
{
printf("test\n");
}


extern void hell();

void test2()
{
hell();
printf("test\n");
}
zylthinking@linux:~/downloads$ gcc -shared a.c -o liba.so
zylthinking@linux:~/downloads$ cat b.c

#include <stdio.h>

extern void test();

void main()
{
test();
}
zylthinking@linux:~/downloads$ gcc b.c -L. -la
./liba.so: undefined reference to `hell'
collect2: error: ld returned 1 exit status

--

※ 来源:·水木社区 http://ift.tt/15tmf2p: 220.181.171.*]


from 水木社区 电脑技术区十大热门话题 http://ift.tt/2s5WpU2
via IFTTT

评论

此博客中的热门博文

丰田将在 2019 东京车展上展出一台超迷你的都市型电动车

[数字家庭] [原创]北京联通IPTV的完美方案

英特尔将推出更多支持 e-SIM 的 modem