简体   繁体   中英

CMake not detecting CXX but detecting CPP files

I'm trying to learn CMake from http://www.cmake.org/cmake/help/cmake_tutorial.html and running into trouble with the first step itself of running a simple file tutorial.cpp.

The issue is that when I have this command in my CMakeLists.txt file

add_executable(Tutorial tutorial.cpp)

it builds fine.

However, when I change it to

add_executable(Tutorial tutorial.cxx)

It gives the following error

-- Configuring done
CMake Error at src/CMakeLists.txt:6 (add_executable):
  Cannot find source file:

    tutorial.cxx

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx


-- Build files have been written to: /home/vaisagh/workspace/Test/build

My directory structure is like this:

.
├── build
├── CMakeLists.txt
└── src
    ├── CMakeLists.txt
    └── tutorial.cpp

2 directories, 3 files

CMakeLists.txt

#Specify the version being used aswell as the language
cmake_minimum_required(VERSION 2.8.11)
#Name your project here
project(Tutorial)
add_subdirectory(src)

src/CMakeLists.txt

#Specify the version being used aswell as the language
cmake_minimum_required(VERSION 2.8.11)
add_executable(Tutorial tutorial.cxx)

Tried extensions .c .C... Indicates that CMake tried to search for tutorial.cxx.c , tutorial.cxx.C , etc.

The source filename given to add_executable must match the actual filename on disc.

  1. Rename tutorial.cpp to tutorial.cxx -or-
  2. Change add_executable(Tutorial tutorial.cxx) to add_executable(Tutorial tutorial.cpp)

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