This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Mixing GNU C89 extern inline and C++ inline on Cygwin?


Hello -- 

I have a project that uses inline functions that need to be usable in code
compiled both as GNU C89 and from C++.

To get the inline functions to work in GNU C89-based code, the project does
the "double-link" trick -- inlcuding the inlined function once as "extern
inline" in the .h file, and then again without any specifiers in the .c
file for the backup definition.  When the .h file is included in C++ code,
the inlined function is specified as "inline" in the C++ semantics.

When optimization is turned on, and thus inline functions are actually
inlined, everything works fine.  However, on Cygwin, when functions are not
inlined, I get link-time errors: the weak symbol emitted for the C++ code
conflicts with the backup definition.  (This problem does not occur on
ELF-based systems, tested on GNU/Linux (RHEL 4) and Solaris 8.)


Is this a gcc bug?

Does anyone have any advice about a way to define my inline functions such
that this problem will not arise?


Simplified test case:

$ gcc -Wall -g -O2 -c inline_conflict_c.c 
$ g++ -Wall -g -O2 -c inline_conflict_cpp.cpp 
$ g++ -Wall -g -O2 -o inline_conflict inline_conflict_c.o inline_conflict_cpp.o
$ ./inline_conflict; echo $?
47

$ gcc -Wall -g -O0 -c inline_conflict_c.c 
$ g++ -Wall -g -O0 -c inline_conflict_cpp.cpp 
$ g++ -Wall -g -O0 -o inline_conflict inline_conflict_c.o inline_conflict_cpp.o
inline_conflict_cpp.o: In function `foo':
/home/Jonathan/Inline-Conflict/inline_conflict.h:23: multiple definition of `_foo'
inline_conflict_c.o:/home/Jonathan/Inline-Conflict/inline_conflict.h:23: first defined here
collect2: ld returned 1 exit status

$ gcc -v
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with: /gcc/gcc-3.4.4/gcc-3.4.4-1/configure --verbose
--prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--enable-languages=c,ada,c++,d,f77,java,objc --enable-nls
--without-included-gettext --enable-version-specific-runtime-libs
--without-x --enable-libgcj --disable-java-awt --with-system-zlib
--enable-interpreter --disable-libgcj-debug --enable-threads=posix
--enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptions
--enable-hash-synchronization --enable-libstdcxx-debug : (reconfigured) 
Thread model: posix
gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)


Attachment: inline_conflict_c.c
Description: Text document

Attachment: inline_conflict_cpp.cpp
Description: Text document

Attachment: inline_conflict.h
Description: Text document

-- 
Jonathan Lennox
lennox@cs.columbia.edu

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]