- I want to create a shared library with the function
my_callback. Because I want to support C programs,dlsym, and C++, I wantmy_callbackto be unmangled; therefore, I put it inmy_callback.h. - I compile my 100%-C library
libmc.so. program-aneedsmy_callbackwithout hard-linking. Becausemy_callbackisn't mangled,dlsymis an option.program-bneedsmy_callbackwith hard-linking. Becausemy_callbackisn't mangled,program-bmust either useextern "C"when includingmy_callback.hormy_callback.hneeds to conditionally useextern "C"if C++ compilation is detected. This is because gcc infers thatmy_callback.his meant to be a C++ header rather than at least implicitly giving it C linkage. The problem isn't apparent until link time, however; gcc mangles the name and an "undefined reference" error occurs.
I use gcc above to point out that it isn't just g++ that will do this.
Kevin Barry
