CMake and non-standard extensions

独自空忆成欢 提交于 2020-06-16 05:23:09

问题


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.

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)

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

What am I doing wrong here?

Thanks!


回答1:


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.

Anyway IMHO CMake should do it automatically.



来源:https://stackoverflow.com/questions/18784811/cmake-and-non-standard-extensions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!