[ODE] Using ODE from C without C++ run-time dependancies.

Adam D. Moss aspirin at ntlworld.com
Wed Jan 8 06:56:01 2003


Hi!

Those developing on Linux with a moderately recent GCC will
probably have noticed that you can't link a non-trivial
ODE-using C application as a pure C application without
a handful of link errors similar to this:

lib/libode.a(collision_kernel.o):/cvs/ode/ode/ode/src/collision_kernel.cpp:54:
undefined reference to `__cxa_pure_virtual'

Linking using g++ rather than gcc works, but your resulting
binary then has a dependancy on libstdc++ and the C++ ABI which
is both unnecessary for a C application and an unpleasant
(ongoing) binary-compatibility black-spot on Linux (possibly
other gcc3-using platforms also).

The workaround is to provide a dummy __cxa_pure_virtual stub,
which should be completely harmless for a C application.

You can do this quite trivially by specifying
--defsym __cxa_pure_virtual=0 to GNU ld (or
-Wl,--defsym,__cxa_pure_virtual=0 to gcc) at the application
linking stage.

Linking drawstuff has deeper problems for C applications without
introducing C++ dependancies, but it's a fair bet that you won't
ever be likely to deploy drawstuff-using application binaries,
least of all pure-C ones.

Good luck,
--Adam
-- 
Adam D. Moss   . ,,^^   adam@gimp.org   http://www.foxbox.org/   co:3
"She felt rudderless and directionless, like the dead
 sheep the November rains had carried down the river."