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

Unable to build with msys2 mingw64 for windows due to error when linking json-patch.exe #335

Open
terablade2001 opened this issue Nov 12, 2024 · 0 comments

Comments

@terablade2001
Copy link

Hi.
I am trying to build this library in windows for MinGW64 with nlohmann/json 3.11.3 version, but it fails at some point.

Starting by the error I get:

[ 47%] Linking CXX executable json-patch.exe
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\json-patch.dir/objects.a(json-patch.cpp.obj):json-patch.cpp:(.text.startup+0x3b): undefined reference to `nlohmann::json_patch::json_patch(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long long, unsigned long long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void>&&)'
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\json-patch.dir/objects.a(json-patch.cpp.obj):json-patch.cpp:(.text.startup+0x7f): undefined reference to `nlohmann::json_patch::json_patch(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long long, unsigned long long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void>&&)'
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\json-patch.dir/objects.a(json-patch.cpp.obj):json-patch.cpp:(.text.startup+0xb9): undefined reference to `nlohmann::json_patch::json_patch(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long long, unsigned long long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void>&&)'
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\json-patch.dir/objects.a(json-patch.cpp.obj):json-patch.cpp:(.text.startup+0xf3): undefined reference to `nlohmann::json_patch::json_patch(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long long, unsigned long long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void>&&)'
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\json-patch.dir/objects.a(json-patch.cpp.obj):json-patch.cpp:(.text.startup+0x228): undefined reference to `nlohmann::json_patch::json_patch(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long long, unsigned long long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void>&&)'
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\json-patch.dir/objects.a(json-patch.cpp.obj):json-patch.cpp:(.text.startup+0x3ec): more undefined references to `nlohmann::json_patch::json_patch(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long long, unsigned long long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void>&&)' follow
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [test\CMakeFiles\json-patch.dir\build.make:100: test/json-patch.exe] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:656: test/CMakeFiles/json-patch.dir/all] Error 2
mingw32-make: *** [Makefile:145: all] Error 2

Question: Is the json-schema-validator compatible up to any specific version of nlohmann/json ?

The procedure I follow is describe below.

Question: Is it ok? Am I missing something?

Trying to build with msys2 mingw64

  1. Use MSYS2 and install it. Then open the executable MSYS2 MINGW64 (there are multiple executables installed).
  2. Execute pacman -Syu and wait. The window will close during updating. If after 1-2 minutes it doesn't open, reopen it.
  3. Execute the rest
pacman -S --needed --noconfirm mingw-w64-x86_64-toolchain
pacman -S --needed --noconfirm mingw-w64-x86_64-make mingw-w64-x86_64-cmake mingw-w64-x86_64-openssl

Now suppose we are working in folder /c/Git/external/.

Build JSON library

Clone the library:

git clone https://github.com/nlohmann/json.git
cd json
git checkout v3.11.3

From the MSYS2 MINGW64 do:

cd /c/Git/external/json
mkdir build
cd build
cmake -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=/c/Git/external/json/install ..
cmake --build . --target install -- -j8

Build the validator library

Clone the library:

git clone https://github.com/pboettch/json-schema-validator
cd json-schema-validator
git checkout 2.3.0

From the MSYS2 MINGW64 do:

cd /c/Git/external/json-schema-validator
mkdir build
cd build
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/c/Git/external/json/install/share/pkgconfig
cmake -G "MinGW Makefiles" -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=/c/Git/external/json-schema-validator/install -DCMAKE_PREFIX_PATH=/c/Git/external/json/install ..
cmake --build . --target install -- -j8

Then the initial provided error occurs.

Notes

  • JSON library less than 3.11.3 can't be build with the same way. However after required local updates on some files I succeed to build JSON version 3.11.2. But again the json-schema-validator failed with the same message.
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

1 participant