I'm using casbin-cpp as a dependency in another CMake project alongside another library that also depends on a different version of nlohmann_json. This results in undefined symbol errors caused by an ABI mismatch. The issue is that casbin/CMakeLists.txt links with nlohmann_json as PRIVATE, however nlohmann_json is part of casbin's public API. These three headers include <nlohmann/json.hpp and expose nlohmann::json types directly:
- include/casbin/casbin_types.h
- include/casbin/model/evaluator.h
- include/casbin/data_types.h
Since the linkage is PRIVATE, CMake doesn't propagate casbin's nlohmann_json target downstream to consumers and when another dependency brings in a different version, the compiler resolves casbin's headers against the wrong version, leading to ABI mismatches at link time.
The fix would be to change PRIVATE to PUBLIC:
-target_link_libraries(casbin PRIVATE nlohmann_json::nlohmann_json)
+target_link_libraries(casbin PUBLIC nlohmann_json::nlohmann_json)
Happy to open a PR for this.