2

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!

cpp
  • 3,743
  • 3
  • 24
  • 38
user2333829
  • 1,301
  • 1
  • 15
  • 25

1 Answers1

4

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.

Michał Walenciak
  • 4,257
  • 4
  • 33
  • 61