[CMake] Mixing c and c++ with MinGW

Bill Hoffman bill.hoffman at kitware.com
Thu Dec 28 09:21:08 EST 2006


Werner Smekal wrote:
> Hi,
>
> it is normally possible to mix c and c++ in a project with the GNU 
> compiler. Normally you compile c files with gcc and c++ files with g++ 
> and than link all together with g++.
>
> In our project (plplot) we allow c++ code into the mainly c code 
> library under some circumstances - everything works fine, ar links 
> everything together.
>
> We have now c and c++ examples which use this mixed library, but the c 
> examples won't compile with gcc obviously since a lot of c++ stuff is 
> unreferenced.
>
> I tried to set CC to g++, but cmake didn't allow this.
>
> Is there any solution for this problem?
See :

SET_TARGET_PROPERTIES(target1 target2 ...
                        PROPERTIES prop1 value1
                        prop2 value2 ...)
....

The LINKER_LANGUAGE property is used to change the tool used to link an 
executable or shared library. The default is set the language to match 
the files in the library. CXX and C are common values for this property.

You can use that property to link with c++ but compile with c.

-Bill



More information about the CMake mailing list