Multiple definition of... extern inline

用符合C99规范的编译器编译gcc-suite,可以通过c,却不能通过fortran的编译,显示的错位是重复定义。查看gcc的邮件列表,说是bug,但对bug的解释却是不知所云。在下面一篇博客中见到了一个合理的解释:C99标准和C89标准中对inline的解释不一致,glibc头文件中存在inline函数,gcc-suite需要用到这些头文件,于是最后导致编译gcc suite的时候重复定义错误。

Multiple definition of... extern inline

When I tried to compile gnutls-2.6.6, I got a lot of these:

.libs/gnutls_compress.o: In function `__strcspn_c1':
/usr/include/bits/string2.h:972: multiple definition of `__strcspn_c1'
.libs/gnutls_record.o:/usr/include/bits/string2.h:972: first defined here
.libs/gnutls_compress.o: In function `__strcspn_c2':
/usr/include/bits/string2.h:983: multiple definition of `__strcspn_c2'
.libs/gnutls_record.o:/usr/include/bits/string2.h:983: first defined here

It turns out that gnutls decides to enforce ISO C99 standard on all its source files, but a lot of the glibc header files use extern inline, which causes GCC to emit a symbol for each extern inline functions. GCC made a change to the extern inline semantics in GCC 4.3 in order to be ISO C99 compliant.

The fix I chose is to add -fgnu89-inline option to GCC throughout. It can be accomplished by invoking configure script like this:

./configure [config_flags...] CFLAGS=-std=gnu89

(这里原文是:./configure [config_flags...] CFLAGS=-fgnu89-inline,但是在我的机器上不通过,显示错位为不可识别的命令行选项。具体参考gcc对inline的说明http://gcc.gnu.org/onlinedocs/gcc/Inline.html。 gcc-4.1.2不支持-fgnu89-inline选项,gcc-4.1.3起才开始支持。显然,std=gnu89作用域比-fgnu89-inline大,可能造成未知的副作用)

And this solves the problem.

sourece: http://lifecs.likai.org/2009/06/multiple-definition-of-extern-inline.html


你可能感兴趣的:(extern)