I have a very simple library with the following dtructure:
src
- myLib.h
- myLib.cpp
App
- testApp.cpp
CMakelist.txt
cmake_minimum_required(VERSION 3.10)
project(Testing)
# JSON
find_package(nlohmann_json REQUIRED)
add_library(myLib SHARED
src/myLib.cpp
)
target_link_libraries(myLib PUBLIC nlohmann_json::nlohmann_json)
set(CMAKE_BUILD_TYPE debug)
install(TARGETS myLib
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY src/ DESTINATION include FILES_MATCHING PATTERN "*.h")
Building the library works fine but when I link with testApp.cpp, which just includes myLib.h, I get the following errors:
g++ testApp.cpp -o runApp -I ../install/include/ -l ../install/lib/libmyLib.so
./install/include/myLib.h:16:10: fatal error: nlohmann/json.hpp: No such file or directory
16 | #include <nlohmann/json.hpp>
What could be going wrong here?