From 5d797b91e4af6c52b0389260b6cc32383fbdebd9 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Sat, 1 Feb 2020 11:38:25 +0100 Subject: [PATCH] build: use -fcommon when building libnm-core Building with GCC 10 gives the following error: multiple definition of_nm_jansson_json_object_iter_key'; libnm/.libs/liblibnm.a(libnm_core_la-nm-json.o):/builddir/build/BUILD/NetworkManager-1.23.1/libnm-core/nm-json.c:24: first defined here /usr/bin/ld: libnm/.libs/liblibnm.a(libnm_core_la-nm-team-utils.o):/usr/include/jansson.h:202: multiple definition of _nm_jansson_json_object_iter'; This happens because GCC 10 defaults to -fno-common and so multiple definitions of the same global variable are not merged together. _nm_jansson_json_* symbols are defined in nm-json.c as void pointers and, due to the following macros in nm-json.h: #define json_object_iter_next (*_nm_jansson_json_object_iter_next) ... the function declaration in jansson.h: void *json_object_iter_next(json_t *object, void *iter); becomes a global variable as well: void *(*_nm_jansson_json_object_iter_next)(json_t *object, void *iter); So, the symbol is present in nm-json.o and all other object files that include nm-json.h, and -fcommon is required. Without it, it would be necessary to define the symbols only in one place (for example, nm-json.c), but then static inline functions from the jannson.h header would still refer to the original (missing) jansson functions. For the moment, just use -fcommon. (cherry picked from commit d2d6a68697556877b30703e412852ac5032957e9) (cherry picked from commit 311872ddca7b73c88510ec382c65b8e1f3c266f5) --- Makefile.am | 1 + libnm-core/meson.build | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 9a6b310414..f528788312 100644 --- a/Makefile.am +++ b/Makefile.am @@ -963,6 +963,7 @@ libnm_core_libnm_core_la_CPPFLAGS = \ if WITH_JSON_VALIDATION libnm_core_libnm_core_la_CPPFLAGS += $(JANSSON_CFLAGS) +libnm_core_libnm_core_la_CFLAGS = -fcommon endif libnm_core_libnm_core_la_SOURCES = \ diff --git a/libnm-core/meson.build b/libnm-core/meson.build index 9637afaad5..53d91babaa 100644 --- a/libnm-core/meson.build +++ b/libnm-core/meson.build @@ -200,9 +200,12 @@ cflags = [ '-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIBNM_CORE', ] +libnm_core_c_args = cflags + if enable_json_validation libnm_core_sources += files('nm-json.c') deps += jansson_dep + libnm_core_c_args += ['-fcommon'] endif if (crypto_gnutls_dep.found()) @@ -240,8 +243,8 @@ libnm_core = static_library( 'nm-core', sources: libnm_core_sources_all, dependencies: deps, + c_args: libnm_core_c_args, link_with: libnm_crypto, - c_args: cflags, ) libnm_core_dep = declare_dependency(