Can CMake use g++ to compile C files?

后端 未结 3 566
别跟我提以往
别跟我提以往 2020-12-09 11:39

I have worked on a project where I was using g++ to compile C code in files that end in .c. The reason is that I\'m told that g++ has better warning messages.

I am s

相关标签:
3条回答
  • 2020-12-09 12:01

    If you need to switch the whole project, set it in the project directive:

    project(derproject LANGUAGES CXX)
    
    0 讨论(0)
  • You should not override the compiler for this purpose. If you really need to compile your C files as C++ then you should teach cmake that your files belong to C++ language:

    set_source_files_properties(filename.c PROPERTIES LANGUAGE CXX )
    
    0 讨论(0)
  • 2020-12-09 12:09

    To have cmake treat all C files as C++ files use:

    file(GLOB_RECURSE CFILES "${CMAKE_SOURCE_DIR}/*.c")
    SET_SOURCE_FILES_PROPERTIES(${CFILES} PROPERTIES LANGUAGE CXX )
    
    0 讨论(0)
提交回复
热议问题