简体   繁体   English

Cmake找不到它们存在的源文件

[英]Cmake can't find source files where they exists

I have very simple CMakeLists.txt file. 我有非常简单的CMakeLists.txt文件。

cmake_minimum_required (VERSION 2.6)
project (test_proj)

set(TEST_INCLUDE_DIR
    "${PROJECT_SOURCE_DIR}/src")

set(TEST_CPP "${PROJECT_SOURCE_DIR}/src/source_file.cpp"
             "${PROJECT_SOURCE_DIR}/src/main.cpp")

set(TEST_HEADERS
    "${PROJECT_SOURCE_DIR}/src/header.h")

#include_directories(${TEST_INCLUDE_DIR})


add_executable(testproj "${TEST_CPP}" "${TEST_HEADERS}")

And when I run it like that: 当我这样运行时:

mkdir build
cd build
cmake ..

I get next output: 我得到下一个输出:

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

    /home/me/test_proj/src/source_file.cpp;/home/me/test_proj/src/main.cpp

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

But those files: 但那些文件:

/home/me/test_proj/src/source_file.cpp
/home/me/test_proj/src/main.cpp

Are there. 在那儿。 Exactly under that path. 正好在那条道路上。 Why it can't find them? 为什么找不到它们? If I remove any one of them, so TEST_CPP contains just one source file, project generates well. 如果我删除其中任何一个,那么TEST_CPP只包含一个源文件,项目生成良好。 But why it can't if I have more then one source? 但是,如果我有一个以上的来源,它为什么不能呢?

I tried CR LF and just LF as end symbols, result is the same. 我试过CR LF而只是LF作为结束符号,结果是一样的。

cmake version 2.8.12.2 cmake版本2.8.12.2

Don't put quotes around ${TEST_CPP} : 不要在${TEST_CPP}附近加上引号:

add_executable(testproj ${TEST_CPP} ${TEST_HEADERS})

Otherwise it will add the sources as ; 否则它将添加源; separated list. 分开的清单。

And just a hint: you don't need to prefix everything with ${PROJECT_SOURCE_DIR} (it's done automatically by CMake). 只是一个提示:你不需要使用${PROJECT_SOURCE_DIR}为所有内容添加前缀(它由CMake自动完成)。

Reference 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM