Search code examples
c++cmakeclionapple-m1

Can not include linked with CMake third-party library


I am trying to use an fmt library in my C++ project for formatting. I have installed the package with anaconda.

Afterwards, in my CMake file I have found the fmt package and link:

set(fmt_DIR "/opt/anaconda3/lib/cmake/fmt/")
find_package(fmt REQUIRED)
target_link_libraries(<my_target> fmt)

But even though these steps are done, I run into "fatal error: 'fmt' file not found", when trying to #include <fmt>

I am probably missing something obvious. Would appreciate any help.


Solution

  • As @Tsyvarev mentioned in comment:

    ... after find_package(fmt) one should link with fmt::fmt: target_link_libraries(<your-target> fmt::fmt).

    So using target_link_libraries(<your-target> fmt::fmt) instead of target_link_libraries(<your-target> fmt) works perfectly.