I am really not an expert at C/C++ Linking magic. g++ and Cygwin neither, rather a novice indeed.

Imagine I have an executable, (Apache Server in my case), which accepts C library as modules. e.g. compiled file libMyServer.so

If I do the guts coding in C++, and export only vanilla functions, for example static member functions of a class I'd call CExportToC... if I do this will the linking magic make my library libMyServer reachable from a program requesting C libraries ?

Accepted Answer

You don't do that at link time, you declare to the compiler not to mangle names when generating code (which of course disallows overloads). Put the declarations of the things you want to expose to C into an extern "C" { ... } block. See e.g. the FAQ. Classes are pretty much out of luck here, unless you're willing to do a lot of work and live with the PITA. And even then, a single compiler writer can break your code (in ways that will only show in runtime bugs, not in compile errors).

Written by delnan
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki