We write an application mainly in C
but some sub-modules are written in C++
(on Linux). The problem is how to write CMakeLists.txt
files to use g++
for some subdirectories and gcc
for another.
The compiler and linker is usually determined by the file extension if not set otherwise. So as long as the file endings are fine, your code is compiled and linked with the correct compiler.
On a side note, remember to make the correct extern C declarations, if you mix C and C++.
CMake does this automatically. You can freely intermix both types of files in your CMakeLists.txt file:
. . .
add_executable(
my_program
code.cpp
more_code.c
)
I do this all the time and it just works.
You can set LANGUAGE property of your source files to "CXX". See documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With