[CMake] Building a library for both C and C++

Andreas Pakulat apaku at gmx.de
Wed Jan 9 04:27:25 EST 2013


Hi,

On Wed, Jan 9, 2013 at 1:17 AM, kgardenia42 <kgardenia42 at googlemail.com> wrote:
> I am trying to write a CMakeLists.txt where the same source files are
> compiled separately to both a C library and a C++ library.
>
> So, lets say I have foo.c, bar.c and baz.c and I would like to build
> mylib.a and mylib++.a
>
> My intuition is to use one CMakefile and add multiple targets for each
> library I want to build.  Does that seem like a reasonable approach?
> Other suggestions welcome.  Also, can anyone point me to an open
> source library that uses cmake and builds both a C and C++ version.

I'd say this does not make any sense. The mylib++.a will still be a C
library because all the compiled code in it will be C code unless your
c files are somehow using a preprocessor macro to enable C and C++
code. And if they I'd say you'd be better off to split the files into
a .c and a .cpp one and drop the macro.

A C++ program can link to C libraries just fine, so there's really no
need for that that I can see right now.

Andreas


More information about the CMake mailing list