简体   繁体   English

强制CMake使用Visual Studio将C ++编译器用于C文件

[英]Force CMake to use C++ compiler for C files with Visual Studio

I have generated .h and .c files which must be compiled as C++ files with Visual Studio. 我已生成.h和.c文件,必须使用Visual Studio编译为C ++文件。 I heard I could do something like set_source_files_properties( ${SOURCES} PROPERTIES LANGUAGE "CXX" ) . 我听说我可以做类似set_source_files_properties( ${SOURCES} PROPERTIES LANGUAGE "CXX" )事情。 In parallel, I have read that I should not do that as it should used only in exotic situations. 与此同时,我已经读到我不应该这样做,因为它只应该在异国情调中使用。

So, what is the best way to force CMake to generate VS projects which compiles C files as C++ files? 那么,强制CMake生成将C文件编译为C ++文件的VS项目的最佳方法是什么?

PS: renaming the generated files is not an option. PS:重命名生成的文件不是一个选项。

I have been using the individual properties (most likely you can also set directory properties - but this is not as fine grained) without any problems. 我一直在使用各个属性(很可能你也可以设置目录属性 - 但这不是很精细)没有任何问题。 Not for setting the language though (but why should it be any different?): 不是为了设置语言(但为什么它应该是不同的?):

SET_SOURCE_FILES_PROPERTIES( file1.c PROPERTIES LANGUAGE CXX )

This works under Linux and Windows and doesn't seem to pose any problems. 这适用于Linux和Windows,似乎没有任何问题。 What have you heard that makes you hesitate? 你听到了什么让你犹豫不决?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何强制MIDL编译器在Visual Studio 2010中使用“C ++模式”而不是“C模式”? - How to force MIDL compiler to use “C++ mode” instead of “C mode” in Visual Studio 2010? 如何使用Visual Studio C ++编译器? - How to use Visual Studio C++ Compiler? 强制visual studio 2012编译器使用C ++ TR1(2007标准) - Force visual studio 2012 compiler to use C++ TR1 (2007 standard) CMake 找不到 Visual C++ 编译器 - CMake does not find Visual C++ compiler 使用CMake生成Visual Studio C ++项目文件 - Using CMake to generate Visual Studio C++ project files 列出由cmake生成的Visual Studio C ++项目中的头文件 - Listing header files in Visual Studio C++ project generated by cmake 如何在Visual Studio 2017,C ++,CMake中使用数据断点? - How to use data breakpoints in Visual Studio 2017, C++, CMake? Visual Studio C++ 编译器尝试编译 CUDA C/C++ 文件 - Visual Studio C++ compiler tries to compile CUDA C/C++ files 如何使用CMake强制c ++编译器使用不同安装包的版本之一? - How to force c++ compiler use one of different installed package's versions, using CMake? 在netbeans中使用visual studio c ++编译器 - Using visual studio c++ compiler in netbeans
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM