简体   繁体   中英

CMake and non-standard extensions

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM