Repository navigation
Tell to Meson to compile C files with CXX compiler #11603
|
In certain cases, like for example, compiling Catch2 tests with a C language file, you need to tell the compiler to use the C++ compiler to compile the C files (instead of using the CC compiler). In CMake is easily done with I tried already setting the language to |
Replies: 6 comments 10 replies
|
Does the C language file contain C++ code defining the tests? If so, why not name it .cpp instead? If it truly only contains C code but is needed in the binary along with a .cpp file containing the test definition, then is it not sufficient to link both the C functions and the C++ test definitions together using a C++ linker? Meson will do that automatically for targets that contain a mixture of C and C++ source files. |
|
Another option would be (useful if the files belong to some other project and you can't rename them) to |
|
Another option would be to include a C language for the project, but pass |
|
Is this still unsolved? (That is instructing Meson to use CXX for *.c)?
|
|
Meson generally prefers to use conventions over configuration, so for example the extension drives which compiler is used. Can you give an example of this use of liblua with exceptions? Is the use supported in Lua's sources? |
|
Maybe it helps you to know that meson will treat .c files as C code, but .C files as C++ code. |
Is this still unsolved? (That is instructing Meson to use CXX for *.c)?
My use-case is very different from the original question: what I want to do is compile liblua as C++, which allows using C++ features in it, such as using Exceptions instead of longjmp.
c_args: ['-x', 'c++']works as a work-around, but this really is a hack because this requires you to define the C compiler as something that understands C++. It's also somewhat confusing that you have to define both'c'and'c++'for the project andadd_project_arguments()to both languages.