CMake和非标准扩展 [英] CMake and non-standard extensions
问题描述
我有一些C ++源代码,出于正当的理由,这些代码不会以 .cpp或 .cc或任何其他常见的C ++扩展名结尾。我想用CMake将其编译成可执行文件。
I have some C++ source code that, for a valid reason, does not end in ".cpp" or ".cc" or any other usual C++ extension. I would like to compile this into an executable with CMake.
我目前非常简单的CMake脚本是:
My very simple CMake script currently is:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(test)
SET_SOURCE_FILES_PROPERTIES(test_mycode.foo PROPERTIES LANGUAGE CXX)
ADD_EXECUTABLE(test test_mycode.foo)
据我了解,SET_SOURCE_FILES_PROPERTIES(...)应该就是需要使Cmake将 test_mycode.foo识别为C ++文件。但是,当我尝试编译时,它失败并显示以下错误:
As far as I understand, SET_SOURCE_FILES_PROPERTIES(...) should be all that is needed to make Cmake recognize "test_mycode.foo" as a C++ file. However, when I try to compile, it fails with the following error:
/usr/bin/c++ -o CMakeFiles/test.dir/test_mycode.foo.o -c test/test_mycode.foo
c++: test/test_mycode.foo: linker input file unused because linking not done
我在这里做什么错了?
谢谢!
推荐答案
据我所知,CMake已将您的文件用作c ++,但gcc却没有。您还必须告诉CMake向编译器添加额外的标志(请参见此处: http: //gcc.gnu.org/onlinedocs/gcc/Overall-Options.html (用于-x选项),因此它将文件视为c ++代码。
As far as I can see CMake has used your file as c++ one, but gcc didn't. You will also have to tell CMake to add extra flags to compiler (look here: http://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html for -x option) so it will treated your file as c++ code.
无论如何,恕我直言CMake应该自动执行此操作。
Anyway IMHO CMake should do it automatically.
这篇关于CMake和非标准扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!