msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.31k stars 1.23k forks source link

jsoncpp pkgconfig file reports wrong libs for static builds since 1.9.6 update #22584

Closed sharkwouter closed 1 week ago

sharkwouter commented 1 week ago

Description / Steps to reproduce the issue

When building an application which uses jsoncpp statically and linking using the output of pkgconfig --static --libs jsoncpp, linking will fail. This started happening since jsoncpp was updated to version 1.9.6. I am running into this issue with my game OceanPop, available here. Below is a smaller example that should reproduce it.

main.cpp:

#include <string>
#include <json/json.h>
#include <iostream>

int main(void)
{
  Json::Value data;
  Json::Reader reader;
  std::string text = "{\"message\":\"hello json\"}";

  reader.parse(text, data);
  std::cout << data.get("message", "Could not load json message") << "\n";

  return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)

project(hello_json)

set(CMAKE_CXX_FLAGS "-static ${CMAKE_CXX_FLAGS}")

include(FindPkgConfig)
pkg_search_module(JSONCPP Required jsoncpp)

include_directories(${JSONCPP_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${JSONCPP_STATIC_LIBRARIES})

Put these in a directory, then run the following commands there:

mkdir build && cd build
cmake -G "MinGW Makefiles" ..
cmake --build .

Expected behavior

As with jsoncpp version 1.9.5, I was expecting the build to link correctly and result in a working binary.

Actual behavior

As seen in the failure of this GitHub workflow, building with jsoncpp version 1.9.6 results in the following error:

 [100%] Linking CXX executable oceanpop.exe
D:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ljsoncpp: No such file or directory
D:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ljsoncpp: No such file or directory
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [CMakeFiles\oceanpop.dir\build.make:517: oceanpop.exe] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:86: CMakeFiles/oceanpop.dir/all] Error 2
mingw32-make: *** [Makefile:135: all] Error 2

This same code build just fine before the update.

Verification

Windows Version

MINGW64_NT-10.0-20348

Are you willing to submit a PR?

I have contributed before, but I don't know if I'll have time to fix this myself.

mmuetzel commented 1 week ago

Thank you for reporting this issue.

Could you please check if this is resolved if you install the build artifacts from #22585? You can download them from the "Artifacts" drop-down of the "Checks" tab: https://github.com/msys2/MINGW-packages/pull/22585/checks