简体   繁体   English

CMake 错误:致命错误:如果不使用 find_package() 进行升压,则找不到 boost/asio.hpp

[英]CMake Error: fatal error : boost/asio.hpp not found without using find_package() for boost

Like the heading says I don't wanna use the find_package(Boost) to locate Boost and then the Asio component in it rather I want to do by creating a target library, and then link the target to my executable like this就像标题说的那样,我不想使用find_package(Boost)来定位 Boost,然后是其中的Asio组件,而是我想通过创建一个目标库来做,然后像这样将目标链接到我的可执行文件

cmake_minimum_required(VERSION 3.0)
project(final_exe_proj VERSION 1.0)

add_executable(final_exe main.cpp)

find_package(Threads REQUIRED)

add_library(boost_asio INTERFACE)
target_include_directories(boost_asio INTERFACE /usr/local/include/boost/asio.hpp)
target_link_libraries(boost_asio INTERFACE Threads::Threads)

target_link_libraries(final_exe PRIVATE boost_asio)

I have tried doing #include <asio.hpp> but still no luck.我尝试过#include <asio.hpp>但仍然没有运气。 What is the right way to do it?正确的方法是什么? Really would appreciate any help.真的很感激任何帮助。 Thanks!谢谢!

Happy New Year!新年快乐!

Thanks Alan!谢谢艾伦! The issue was in the line target_include_directories问题出在target_include_directories行中

On changing that too关于改变它

target_include_directories(boost_asio INTERFACE /usr/local/include)

In a way this adds to the path for this project, so now the compiler will be able to find #include <boost/asio.hpp>在某种程度上,这增加了这个项目的路径,所以现在编译器将能够找到#include <boost/asio.hpp>

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

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