10 Mar 2009 ta0kira   » (Apprentice)

redi, you misunderstand my point. Take the example below:

  1. 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_callback to be unmangled; therefore, I put it in my_callback.h.

  2. I compile my 100%-C library libmc.so.

  3. program-a needs my_callback without hard-linking. Because my_callback isn't mangled, dlsym is an option.

  4. program-b needs my_callback with hard-linking. Because my_callback isn't mangled, program-b must either use extern "C" when including my_callback.h or my_callback.h needs to conditionally use extern "C" if C++ compilation is detected. This is because gcc infers that my_callback.h is 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

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!