- I want to create a shared library with the function
my_callback. Because I want to support C programs,
dlsym, and C++, I want
my_callbackto be unmangled; therefore, I put it in
- I compile my 100%-C library
my_callbackwithout hard-linking. Because
dlsymis an option.
my_callbackwith hard-linking. Because
program-bmust either use
extern "C"when including
my_callback.hneeds to conditionally use
extern "C"if C++ compilation is detected. This is because gcc infers that
my_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.