首页 > 解决方案 > 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

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. What is the right way to do it? Really would appreciate any help. Thanks!

Happy New Year!

标签: c++boostcmakeboost-asio

解决方案


谢谢艾伦!问题出在target_include_directories行中

关于改变它

target_include_directories(boost_asio INTERFACE /usr/local/include)

在某种程度上,这增加了这个项目的路径,所以现在编译器将能够找到#include <boost/asio.hpp>


推荐阅读