0

When I use the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)
add_library (mylib STATIC)
target_sources (mylib PRIVATE
   myfile.c
)

I get this output in Visual Studio:

 [1/2] Building C object CMakeFiles\lidardump.dir\myfile.c.obj
 [2/2] Linking C static library lidardump.lib

However myfile.c is C++ code. How do I instruct CMake to compile and link all .c files as C++?

I would prefer to not rename the files since they are from another programmer using gcc.

Andy
  • 3,251
  • 4
  • 32
  • 53
  • 1
    You should use some compiler option to do so. It depends on the compiler. `-x c++` option maybe useful for GCC. By the way, why not name your files as `myfile.cpp`? – MikeCAT Jun 28 '21 at 13:24
  • Does https://stackoverflow.com/questions/59348579/how-do-i-override-the-by-extension-type-of-a-file-in-cmake answer your question? Does https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_SOURCE_FILE_EXTENSIONS.html ? – KamilCuk Jun 28 '21 at 13:26

0 Answers0