This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
re: extern "C" applied liberally?
I somewhat tracked down the odd/dubious reason extern "C" is "good".
Some wierd interaction on Darwin with Apple's gcc and gdb.
Breakpoints don't work on non-extern "C", at least if a library is involved.
This isn't necessarily a problem with gcc, or current gcc, or non-Apple gcc,
or gdb, or non-Apple gdb, but somewhere in the Apple gcc/gdb.
Reported here for followup to my suggestion of liberal use of extern "C".
? (which I have applied to our fork and it does help)
1.c
#include "1.h"
int main()
{
?F1();
}
2.c
#ifdef EXTERNC
extern "C" {
#endif
static void F2(void) { }
void F1(void) { F2(); }
#ifdef EXTERNC
}
#endif
1.h
#ifdef EXTERNC
extern "C" {
#endif
void F1(void);
#ifdef EXTERNC
}
#endif
$ rm -rf a.out*
$ g++ -g -c 1.c 2.c
$ rm lib2.a
$ ar rc lib2.a 2.o
$ rm 2.o
$ g++ -g 1.o -L. -l2
$ gdb ./a.out
GNU gdb 6.3.50-20050815 (Apple version gdb-966) (Tue Mar 10 02:43:13 UTC 2009)
...
(gdb) break F2
Function "F2" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) break F1
Function "F1" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) q
$ g++ -g -c 1.c 2.c -DEXTERNC
$ rm 2.o
$ rm lib2.a
$ g++ -g -c 1.c 2.c -DEXTERNC
$ ar rc lib2.a 2.o
$ g++ -g 1.o -L. -l2
$ gdb ./a.out
GNU gdb 6.3.50-20050815 (Apple version gdb-966) (Tue Mar 10 02:43:13 UTC 2009)
...
(gdb) break F2
Breakpoint 1 at 0x1fae: file 2.c, line 4.
(gdb) break F1
Breakpoint 2 at 0x1fb6: file 2.c, line 5.
(gdb) q
Using Apple's gcc-4.2 didn't help.
Strange.
(In reality, the library is libbackend.a)
$ g++ -v
Using built-in specs.
Target: i686-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5493~1/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic --host=i686-apple-darwin9 --target=i686-apple-darwin9
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5493)
I could try with my own gcc.
But maybe it is a matter of flags to gcc/ar/ld.
?- Jay