2016-10-31 73 views
0
./dir/ 
├── bot_example 
│   ├── CMakeLists.txt 
│   └── example0.cpp 
├── CMakeLists.txt 
├── README.md 
└── sleepy_discord 
    ├── attachment.cpp 
    ├── attachment.h 
    ├── channel.cpp 
    ├── etc... 

我正在將一個純視覺工作室的項目重構到CMake中,以使它跨平臺。我在CMake方面沒有廣泛的經驗,但是這個結構在一個測試項目中工作到調試結束。它沒有包含第一個頭文件(attachment.h和我似乎無法識別它。我已經搜索了其他答案,但同樣的問題,但沒有用,任何和所有幫助表示讚賞。CMake - Attachment.h:沒有這樣的文件或目錄

編輯:我應該提到這個工程的窗戶下,這就是爲什麼我很困惑,並深入到堆棧交易所

頂級的CMakeLists.txt

# Project Initialization 
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) 
Project("Sleepy-Discord") 

# Component Initialization 
add_subdirectory(sleepy_discord) 
add_subdirectory(bot_example) 

./sleepy_discord/CMakeLists.txt

# Initialize API 
cmake_minimum_required(VERSION 3.5) 

set(Boost_USE_STATIC_LIBS  ON) 
set(Boost_USE_MULTITHREADED ON) 
set(Boost_USE_STATIC_RUNTIME OFF) 
SET(BOOST_MIN_VERSION "1.58.0") 
FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} REQUIRED) 

FIND_PACKAGE(CURL) 

SET (sleepy_discord_SOURCES 
    ./attachment.cpp 
    ./attachment.h 

    ./channel.cpp 
    ./channel.h 

    ./client.cpp 
    ./client.h 

    ./common.cpp 
    ./common.h 

    ./default_functions.cpp 

    ./discord_object_interface.cpp 
    ./discord_object_interface.h 

    ./embed.cpp 
    ./embed.h 

    ./error.h 

    ./experimental.cpp 
    ./experimental.h 

    ./json.c 
    ./json.h 

    ./json_wrapper.cpp 

    ./message.cpp 
    ./message.h 

    ./sd_error.cpp 

    ./server.cpp 
    ./server.h 

    ./sleepy_discord.h 

    ./user.cpp 
    ./user.h 
) 

if(Boost_FOUND) 
add_library(sleepy_discord ${sleepy_discord_SOURCES}) 
target_include_directories(sleepy_discord INTERFACE 
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>" 
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>" 
    "$<BUILD_INTERFACE:${Boost_INCLUDE_DIRS}>" 
    "$<BUILD_INTERFACE:${CURL_INCLUDE_DIR}>" 
    "$<BUILD_INTERFACE:>${OPENSSL_INCLUDE_DIR}" 
    "$<BUILD_INTERFACE:>${CPR_INCLUDE_DIR}" 
) 
else() 
    message(STATUS "Boost library not found.") 
endif() 

./bot_example/CMakeLists.txt

# Initialize Bot 
cmake_minimum_required(VERSION 3.5) 

set(bot_example_SOURCES 
    ${CMAKE_CURRENT_SOURCE_DIR}/example0.cpp 
) 

add_executable(bot_example ${bot_example_SOURCES}) 
target_link_libraries(bot_example sleepy_discord) 

端子輸出:

Scanning dependencies of target sleepy_discord 
[ 5%] Building CXX object sleepy_discord/CMakeFiles/sleepy_discord.dir/attachment.cpp.o 
/home/bleugamer/Development/bots/sleepy_discord/sleepy_discord/attachment.cpp:1:24: fatal error: Attachment.h: No such file or directory 
compilation terminated. 
sleepy_discord/CMakeFiles/sleepy_discord.dir/build.make:62: recipe for target 'sleepy_discord/CMakeFiles/sleepy_discord.dir/attachment.cpp.o' failed 
make[2]: *** [sleepy_discord/CMakeFiles/sleepy_discord.dir/attachment.cpp.o] Error 1 
CMakeFiles/Makefile2:85: recipe for target 'sleepy_discord/CMakeFiles/sleepy_discord.dir/all' failed 
make[1]: *** [sleepy_discord/CMakeFiles/sleepy_discord.dir/all] Error 2 
Makefile:83: recipe for target 'all' failed 
make: *** [all] Error 2 
+0

而是明確說明你的CMakeLists.txt源文件,你可以使用通配符文件,讓CMake的收集您的烴源文件中的文件: 'FILE(GLOB SOURCES_FILES「 * .cpp「)' '文件(GLOB HEADER_FILES」* .h「)' 'SET(ALL_SOURCES $ {SOURCES_FILES} $ {HEADER_FILES})' –

+1

@ vr.one這是不推薦的,因爲cmake只更新如果cmake文件已更改,則在構建時間。顯式文件發現在大多數大型項目中都是標準的。 Globing是一個臨時性的解決方案,我這是一個長期的項目。 – BleuGamer

+0

@ vr.one它不一定是件好事,因爲它強制CMake在每個版本上運行。 – arrowd

回答

2

在類Unix系統(當然,關於EXT,UFS等 「Unixy」 文件系統,是精確的)文件訪問是區分大小寫的。更改

#include "Attachment.h" 

#include "attachment.h" 
+0

已經全部小寫了。 – BleuGamer

+0

@BleuGamer你的錯誤信息說不是。 – arrowd

+0

我可能是個白癡。謝謝你的收穫。 – BleuGamer

相關問題