【问题标题】:CMake not detecting CXX but detecting CPP filesCMake 不检测 CXX 但检测 CPP 文件
【发布时间】:2014-09-22 03:26:54
【问题描述】:

我正在尝试从 http://www.cmake.org/cmake/help/cmake_tutorial.html 学习 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)

src/CMakeLists.txt

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

【问题讨论】:

    标签: c++ cmake detect


    【解决方案1】:

    Tried extensions .c .C...表示CMake尝试搜索tutorial.cxx.ctutorial.cxx.C等。

    提供给add_executable 的源文件名必须与光盘上的实际文件名匹配。

    1. tutorial.cpp 重命名为tutorial.cxx -或-
    2. add_executable(Tutorial tutorial.cxx) 更改为add_executable(Tutorial tutorial.cpp)

    【讨论】:

    • 谢谢!如果使用第三个想法呢?将行更改为 add_executable(Tutorial tutorial) 这可以很好地构建项目。但我不确定这是否有问题。
    • 我可以想象一个问题,如果您不小心在该目录中创建了一个tutorial.c 文件,那么您的构建将根据 CMake 的后缀搜索顺序成功或失败。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    • 2012-04-02
    • 2018-05-18
    • 1970-01-01
    相关资源
    最近更新 更多