Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jsoncpp does not link to Drogon #2212

Open
usernameawesome opened this issue Nov 25, 2024 · 3 comments
Open

Jsoncpp does not link to Drogon #2212

usernameawesome opened this issue Nov 25, 2024 · 3 comments

Comments

@usernameawesome
Copy link

usernameawesome commented Nov 25, 2024

Using FetchContent, Drogon isn't building due to an issue finding Jsoncpp. This is a bug as Jsoncpp should be imported similar to Trantor, as a submodule. It seems to be required to add Jsoncpp yourself like described below.

By itself in CMakeLists.txt, Jsoncpp builds and runs fine:

FetchContent_Declare(
    jsoncpp
    GIT_REPOSITORY https://github.com/open-source-parsers/jsoncpp
    GIT_TAG 1.9.4
)
...
FetchContent_MakeAvailable(jsoncpp)
...
target_link_libraries(${PROJECT_NAME} PRIVATE jsoncpp_lib)

However Drogon does not seem to find it, specifically in FindJsoncpp.cmake with error:

CMake Error at .../cmake-3.30.4/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
  Could NOT find Jsoncpp (missing: JSONCPP_INCLUDE_DIRS JSONCPP_LIBRARIES)
Call Stack (most recent call first):
  .../cmake-3.30.4/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
  build/_deps/drogon-src/cmake_modules/FindJsoncpp.cmake:36 (find_package_handle_standard_args)
  build/_deps/drogon-src/CMakeLists.txt:189 (find_package)

The include directory can be manually fixed with set(CMAKE_INCLUDE_PATH "${CMAKE_CURRENT_BINARY_DIR}/_deps/jsoncpp-src/include") however I cannot find a way to fix find_library(JSONCPP_LIBRARIES ...). The find_library method is looking for a *.a or *.so file I believe which does not exist in any of the built Jsoncpp directories. Is there a way to download Jsoncpp using FetchContent? It seems the only solution I have found, which I haven't tested yet, is to manually download Jsoncpp.

Desktop (please complete the following information):

  • OS: Ubuntu 18.04 (WSL2)

CMakeLists file:

cmake_minimum_required(VERSION 3.30.4)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(tst VERSION 0.1)
file(MAKE_DIRECTORY /build)
include(FetchContent)
include(FindPkgConfig)

FetchContent_Declare(
    jsoncpp
    GIT_REPOSITORY https://github.com/open-source-parsers/jsoncpp
    GIT_TAG 1.9.4
)

FetchContent_Declare(
    drogon
    GIT_REPOSITORY https://github.com/drogonframework/drogon.git
    GIT_TAG v1.9.8
)
FetchContent_MakeAvailable(jsoncpp)
FetchContent_MakeAvailable(drogon)

add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} PRIVATE drogon jsoncpp_lib)
@NullUserException
Copy link

Have you tried just installing the libjsoncpp-dev package, i.e.:

sudo apt install libjsoncpp-dev

I would also undo any changes made to the cmake build files

@usernameawesome
Copy link
Author

@NullUserException At the time of posting the original message I haven't which is what I meant by It seems the only solution I have found, which I haven't tested yet, is to manually download Jsoncpp. I tried afterward and it also wouldn't get picked up by FindJsoncpp.cmake.

@NullUserException
Copy link

I spun up an instance running Ubuntu 22.04 and I was running into the same problem (Could NOT find Jsoncpp (missing: JSONCPP_INCLUDE_DIRS JSONCPP_LIBRARIES)), but that was fixed when I installed libjsoncpp-dev

Did you make any changes to the cmake files?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants