【发布时间】:2020-04-01 12:35:46
【问题描述】:
所以我的目录结构是这样的
/
-- CMakeLists.txt
-- bencode/
---- bType.hpp
---- bType.cpp
---- Decoder.hpp
---- Decoder.cpp
---- CMakeLists.txt
-- torrent/
---- main.cpp
---- Torrent.hpp
---- Torrent.cpp
---- Tracker.hpp
---- Tracker.cpp
---- CMakeLists.txt
根 CMakeLists.txt 是
cmake_minimum_required(VERSION 3.16)
project(Torrent VERSION 1.0.0)
add_subdirectory(bencode)
add_subdirectory(torrent)
bencode/CMakeLists.txt是
add_library(
Decoder
Decoder.hpp
Decoder.cpp
)
add_library(
bType
bType.hpp
bType.cpp
)
target_include_directories(bType PRIVATE "${CMAKE_CURRENT_SOURCE/_DIR}")
target_include_directories(Decoder PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
torrent/CMakeLists.txt 是
add_library(
Torrent
Torrent.hpp
Torrent.cpp
)
add_library(
Tracker
Tracker.hpp
Tracker.cpp
)
add_executable(main main.cpp)
target_link_libraries(
main PRIVATE
Torrent Tracker
Decoder bType
)
每当我构建时,Torrent.cpp 编译失败,因为它包含不在同一目录中的Decoder.hpp,并且构建命令在编译过程中不包含路径
[build] ../torrent/Torrent.cpp:5:10: fatal error: Decoder.hpp: No such file or directory
[build] #include <Decoder.hpp>
[build] ^~~~~~~~~~~~~
[build] comp
编译时应该有一个-I 标志,但没有。
帮我找出原因?
【问题讨论】:
标签: c++ build cmake compiler-errors