I am requesting all your help and/or advise on a strange issue I am encountering trying to understand Conan.
First thing first, the error :
A well-known : /bin/ld: cannot find -lnlohmann_json_schema_validator
What I am trying to do : Trying to build the main example of the json-schema-validator, based on nlohmann_json, using cmake and conan package manager.
Links :
The CMakeLists.txt is pretty simple :
cmake_minimum_required(VERSION 3.10)
project(app VERSION 1.0.0 LANGUAGES CXX)
add_executable(${PROJECT_NAME} src/main.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/master/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake")
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
# Point 1
conan_cmake_run(REQUIRES json-schema-validator/2.1.0 BASIC_SETUP BUILD missing)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
# Point 2
target_include_directories(${PROJECT_NAME} PUBLIC "src")
From this point on, I searched and found different pieces of information :
- https://stackoverflow.com/a/34256630/7135482 : established that a library is not found by /bin/ld at linking, but as I am using default configuration for everything (Conan profile, Cmake, etc) and wanting the library as static during compilation, I am wondering why /bin/ld cannot find the library located in
/home/<user>/.conan/data/json-schema-validator/2.1.0/_/_/package/feb79143ef49afa1ac08f157e4ea835476439057/lib
... Seems pretty accurate on conan side, from my point of view... why wouldn't it give CMake a correct path when building Makefiles ? - I changed the CMakeLists.txt (between "Point 1" and "Point 2"), thinking it was the use of the "unrecommanded"
conan_cmake_run(...)
. So I changed it according to the documentation on Github
conan_cmake_configure(REQUIRES json-schema-validator/2.1.0
GENERATORS cmake)
conan_cmake_autodetect(settings)
conan_cmake_install(PATH_OR_REFERENCE .
BUILD missing
REMOTE conan-center
SETTINGS ${settings})
(here I get the error fatal error: nlohmann/json-schema.hpp: No such file or directory
. So, it seems this way of doing thing doesn't even #include the files)
- the only way I got the library and its example to work is by by-passing Conan completely..., by cloning nlohmann_json repo and json-schema-validation repo into a vendor folder and by adding them to CMake system as following :
#add_subdirectory(vendor/json)
#add_subdirectory(vendor/json-schema-validator)
#target_link_libraries(${PROJECT_NAME} nlohmann_json::nlohmann_json nlohmann_json_schema_validator)
But what is the point of trying to make my life easier using a package manager if the only way to make my project build, is to avoid the use of the package manager ?
Does someone already encountered this type of issue ? or have another idea I could try or change ?
Any help will be highly appreciated ! SO, thanks in advance !