-
Notifications
You must be signed in to change notification settings - Fork 2.7k
'JSON_HAS_INT64' macro redefined #1672
Description
When we (protobuf team) try to upgrade from bazel 8 to bazel 9, our test fails with:
external/jsoncpp+/include/json/config.h:125:9: error: 'JSON_HAS_INT64' macro redefined [-Werror,-Wmacro-redefined]
125 | #define JSON_HAS_INT64
| ^
:3:9: note: previous definition is here
3 | #define JSON_HAS_INT64 1
| ^
1 error generated.
ERROR: /workspace/build/out/external/jsoncpp+/BUILD.bazel:7:11: Compiling src/lib_json/json_writer.cpp failed: (Exit 1): clang-18 failed: error executing CppCompile command (from cc_library rule target @@jsoncpp+//:jsoncpp)
(cd /workspace/build/out/sandbox/processwrapper-sandbox/81/execroot/main &&
exec env -
PATH=/bin:/usr/bin:/usr/local/bin
***
/usr/local/bin/clang-18 -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics -fno-omit-frame-pointer '-std=c++17' -MD -MF bazel-out/k8-fastbuild/bin/external/jsoncpp+/objs/jsoncpp/json_writer.pic.d '-frandom-seed=bazel-out/k8-fastbuild/bin/external/jsoncpp+/objs/jsoncpp/json_writer.pic.o' -fPIC -iquote external/jsoncpp+ -iquote bazel-out/k8-fastbuild/bin/external/jsoncpp+ -Iexternal/jsoncpp+/include -Ibazel-out/k8-fastbuild/bin/external/jsoncpp+/include -Wpointer-arith -Werror -Wno-sign-compare -Wno-sign-conversion '-Wno-error=sign-conversion' -Wno-deprecated-declarations '-std=c++17' -Woverloaded-virtual '-DJSON_USE_EXCEPTION=0' -DJSON_HAS_INT64 -c external/jsoncpp+/src/lib_json/json_writer.cpp -o bazel-out/k8-fastbuild/bin/external/jsoncpp+/objs/jsoncpp/json_writer.pic.o -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE="redacted"' '-D__TIMESTAMP="redacted"' '-D__TIME="redacted"' '-fmodule-name=jsoncpp+//:jsoncpp' '-fmodule-map-file=bazel-out/k8-fastbuild/bin/external/jsoncpp+/jsoncpp.cppmap' -Xclang -fno-cxx-modules -fmodules-strict-decluse -Wprivate-header '-fmodule-map-file=external/rules_cc++cc_configure_extension+local_config_cc/module.modulemap' '-fmodule-map-file=bazel-out/k8-fastbuild/bin/external/jsoncpp+/private.cppmap')
We've removed -DJSON_HAS_INT64 in our config but the command line still show -DJSON_HAS_INT64. I am not 100% sure but seems like related to the conflict:
1, The Source Code (config.h): Hard-codes #define JSON_HAS_INT64 in line 125
2, The Build Script (BUILD.bazel): Explicitly adds -DJSON_HAS_INT64 to the compiler command line based on its own detection logic at line 52
Protobuf's test can pass if change #define JSON_HAS_INT64 to #ifndef JSON_HAS_INT64 in jsoncpp/include/json/config.h file:
--- a/include/json/config.h
+++ b/include/json/config.h
@@ -122,7 +122,9 @@
#endif // if defined(_MSC_VER)
using LargestInt = Int64;
using LargestUInt = UInt64;
+#ifndef JSON_HAS_INT64
#define JSON_HAS_INT64
+#endif
#endif // if defined(JSON_NO_INT64)
template
Just created a PR for this, please help to review. Thanks