Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ CMake不检测CXX,但检测CPP文件_C++_Cmake_Detect - Fatal编程技术网

C++ CMake不检测CXX,但检测CPP文件

C++ CMake不检测CXX,但检测CPP文件,c++,cmake,detect,C++,Cmake,Detect,我正试图从中学习CMake,但在运行简单文件tutorial.cpp的第一步中遇到了麻烦 问题是当我在CMakeLists.txt文件中有这个命令时 add_executable(Tutorial tutorial.cpp) 它建造得很好 但是,当我将其更改为 add_executable(Tutorial tutorial.cxx) 它给出了以下错误 -- Configuring done CMake Error at src/CMakeLists.txt:6 (add_executabl

我正试图从中学习CMake,但在运行简单文件tutorial.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)
#Specify the version being used aswell as the language
cmake_minimum_required(VERSION 2.8.11)
add_executable(Tutorial tutorial.cxx)
src/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)
#Specify the version being used aswell as the language
cmake_minimum_required(VERSION 2.8.11)
add_executable(Tutorial tutorial.cxx)

tested extensions.c.c..
表示CMake试图搜索
tutorial.cxx.c
tutorial.cxx.c

指定给
add_executable
的源文件名必须与光盘上的实际文件名匹配

  • tutorial.cpp
    重命名为
    tutorial.cxx
    -或-
  • 添加可执行文件(Tutorial Tutorial.cxx)
    更改为
    添加可执行文件(Tutorial Tutorial.cpp)

  • 谢谢如果使用第三种想法呢?将行更改为添加_可执行文件(教程),这样可以很好地构建项目。但我不确定这是否存在一些问题。我可以想象,如果您意外地在该目录中创建了
    tutorial.c
    文件,那么您的构建将根据CMake的后缀搜索顺序成功或失败。