How to fix an issue with Conan not creating package targets that can be found by CMake

I’m encountering linker errors when trying to use Boost::filesystem with Conan package manager and CMake. I’ve successfully installed Boost via Conan, but I’m unable to link against Boost::filesystem. Here are the details:

This is my project/conanfile.txt :

[requires]
boost/1.86.0

[generators]
CMakeDeps
CMakeToolchain

To install dependencies, I navigate to the root directory (cd project) and run:
conan install . -of=external --build=MISSING

which outputs:

======== Finalizing install (deploy, generators) ========
conanfile.txt: Writing generators to <redacted>/TestProject/external
conanfile.txt: Generator 'CMakeDeps' calling 'generate()'
conanfile.txt: CMakeDeps necessary find_package() and targets for your CMakeLists.txt
    find_package(Boost)
    target_link_libraries(... boost::boost)
conanfile.txt: Generator 'CMakeToolchain' calling 'generate()'
conanfile.txt: CMakeToolchain generated: conan_toolchain.cmake
conanfile.txt: CMakeToolchain: Preset 'conan-release' added to CMakePresets.json.
    (cmake>=3.23) cmake --preset conan-release
    (cmake<3.23) cmake <path> -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake  -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release
conanfile.txt: CMakeToolchain generated: <redacted>/TestProject/external/CMakePresets.json
conanfile.txt: CMakeToolchain generated: <redacted>/TestProject/CMakeUserPresets.json
conanfile.txt: Generating aggregated env files
conanfile.txt: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
Install finished successfully

This successfully installs all dependencies (and transitive dependencies). The issue I’m having relates to linking the libraries from Boost. In my project/CMakeLists.txt

cmake_minimum_required(VERSION 3.29)
project(TestProject)

add_executable(TestProject main.cpp)

find_package(Boost)

set(Boost_FILESYSTEM_LIB_PATH ${Boost_INCLUDE_DIRS}/../lib/libboost_filesystem.a)

target_include_directories(TestProject PUBLIC ${Boost_INCLUDE_DIRS})

target_link_libraries(TestProject
        PUBLIC
        # This works
        Boost::boost
        # This works (When commented out, linker error below occurs)
        #${Boost_FILESYSTEM_LIB_PATH}
        # Using this to link introduces linker errors
        Boost::filesystem
)

Here is the code which attempts to use filesystem symbols project/main.cpp:

#include <iostream>
#include <boost/filesystem.hpp>

int main()
{
  auto ret = boost::filesystem::exists("/foo");
  std::cout << ret << std::endl;
  return 0;
}

I now run the program. The general structure of the project is as follows:

project/CMakeLists.txt
project/external (Conan output folder)
project/main.cpp
project/build

To build (via terminal) using Makefile:

cd project/build
cmake -DCMAKE_TOOLCHAIN_FILE=external/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug ..
make 

Here is the linker error output when attempting to link via Boost::filesystem:

[ 50%] Building CXX object CMakeFiles/TestProject.dir/main.cpp.o
[100%] Linking CXX executable TestProject
Undefined symbols for architecture arm64:
  "boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
      boost::filesystem::exists(boost::filesystem::path const&) in main.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Here is the output when attempting to link via ${Boost_FILESYSTEM_LIB_PATH:

[ 50%] Building CXX object CMakeFiles/TestProject.dir/main.cpp.o
[100%] Linking CXX executable TestProject
[100%] Built target TestProject

I have attempted to change the line:

find_package(Boost) to: find_package(Boost REQUIRED COMPONENTS filesystem) to no avail.

How can I resolve these linker errors (instead of using explicit library pathing)? I have read the Conan tutorials and watched a few videos. I have encountered it with several libraries. I am still learning how to use Conan, so I may be missing something painfully obvious. Thank you for any assistance.

7

You can’t change settings like CMAKE_BUILD_TYPE on the cmake command line when using Conan, you’ve installed release packages with conan install but when you change the build type to debug, the Conan targets will be generated to link to the non-existant debug versions of the libraries (you don’t get an error as Conan ends up using undefined variables which cmake just ignores).

You should either setup a separate Conan profile for debug builds or set the debug setting during Conan install:

conan install . -of=external --build=MISSING -s build_type=debug

See https://docs.conan.io/2/tutorial/consuming_packages/different_configurations.html

If you want to still use the release packages then you can use:

conan install . -of=external --build=MISSING -s &:build_type=Debug -s build_type=Release

You’ll need to make sure that the debug and release packages have the same ABI before doing this (they don’t with MSVC).

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật