Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CMake not finding header files

This is a very basic CMake question. I installed xlsxwriter library with brew install xlsxwriter, which adds the library to the system: /usr/local/lib/libxlsxwriter.dylib and the header (a symlink) to /usr/local/include/xlsxwriter.h.
Then, I have the following minimal CMakeLists.txt:

cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(main)
add_executable(${PROJECT_NAME} "main.cpp")
find_library(XLSXWRITER_LIB xlsxwriter)
message(${XLSXWRITER_LIB})
target_link_libraries(${PROJECT_NAME} PUBLIC ${XLSXWRITER_LIB})

I can verify by the message that the system correctly finds the library.
Then, to test, I have this minimum main.cpp:

#include <xlsxwriter.h>

int main() { return 0; }

However, trying to run it produces the following error: "fatal error: ‘xlsxwriter.h’ file not found".

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Can anyone help me see what I’m not doing right?

Thanks

>Solution :

libxlsxwriter ships with a pkg-config file, so you can just use the PkgConfig module:

find_package(PkgConfig REQUIRED)
pkg_check_modules(Xlsxwriter REQUIRED IMPORTED_TARGET xlsxwriter)
target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::Xlsxwriter)

This automatically sets up the linker path, linker libraries, and include path for you.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading