2014-09-22 116 views
1

我想從http://www.cmake.org/cmake/help/cmake_tutorial.html學習CMake,並遇到運行簡單文件tutorial.cpp的第一步本身的麻煩。CMake沒有檢測到CXX,但檢測到CPP文件

的問題是,當我在我的CMakeLists.txt有這個命令文件

add_executable(Tutorial tutorial.cpp) 

它建立的罰款。

然而,當我將其更改爲

add_executable(Tutorial tutorial.cxx) 

它提供了以下錯誤

-- 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 

我的目錄結構是這樣的:

. 
├── 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) 

回答

3

Tried extensions .c .C...表示CMake的試圖搜索tutorial.cxx.ctutorial.cxx.C

給予add_executable必須在光盤上的實際文件名相匹配的源文件名。

  1. 重命名tutorial.cpptutorial.cxx - 或 -
  2. 變化add_executable(Tutorial tutorial.cxx)add_executable(Tutorial tutorial.cpp)
+0

謝謝!如果使用第三個想法呢?將行更改爲add_executable(教程教程)這樣可以很好地構建項目。但我不確定這是否有問題。 – vaisaghvt 2014-09-22 04:11:15

+0

我可以想象一個問題,如果您不小心在該目錄中創建了一個'tutorial.c'文件,那麼您的構建將成功或失敗,取決於CMake的後綴搜索順序。 – mythagel 2014-09-22 05:05:02