From 4199c59c4ceb53f00f87b6d8a4eaa45db78358cf Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 27 Feb 2019 00:48:12 +0300 Subject: [PATCH] Fix 'duplicate symbol' error for tests using multiple static libs (OS X) Issue #263 (bdwgc). If configured with --enable-static, libtool passes libgc.a to gcc twice (with a relative path and with an absolute one) when linking tests that depend on libcord.a, libgccpp.a or libstaticrootslib_test.a which, in turn, depends on libgc.a. Double specification of libgc.a seems to confuse ld tool of MacOS 10.14. The workaround is to omit libgc.la in *_LDADD specification of the mentioned tests when the shared libraries are not requested, at least. * configure.ac (ENABLE_SHARED): New AM_CONDITIONAL. * cord/cord.am (cordtest_LDADD): Do not add libgc.la unless ENABLE_SHARED; add comment. * tests/tests.am (staticrootstest_LDADD): Likewise. * tests/tests.am [CPLUSPLUS && !AVOID_CPP_LIB] (test_cpp_LDADD): Likewise. --- configure.ac | 2 ++ cord/cord.am | 8 +++++++- tests/tests.am | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 1d92e2b..49af362 100644 --- a/configure.ac +++ b/configure.ac @@ -964,6 +964,8 @@ AC_ARG_ENABLE(docs, [do not build and install documentation])]) AM_CONDITIONAL(ENABLE_DOCS, test x$enable_docs != xno) +AM_CONDITIONAL(ENABLE_SHARED, test x$enable_shared = xyes) + # Atomic Ops # ---------- diff --git a/cord/cord.am b/cord/cord.am index 50fa104..c2ea532 100644 --- a/cord/cord.am +++ b/cord/cord.am @@ -19,7 +19,13 @@ libcord_la_SOURCES = \ TESTS += cordtest$(EXEEXT) check_PROGRAMS += cordtest cordtest_SOURCES = cord/tests/cordtest.c -cordtest_LDADD = $(top_builddir)/libgc.la $(top_builddir)/libcord.la +cordtest_LDADD = $(top_builddir)/libcord.la + +## In case of static libraries build, libgc.a is already referenced in +## dependency_libs attribute of libcord.la file. +if ENABLE_SHARED +cordtest_LDADD += $(top_builddir)/libgc.la +endif EXTRA_DIST += \ cord/tests/de.c \ diff --git a/tests/tests.am b/tests/tests.am index 19046e0..93f4b27 100644 --- a/tests/tests.am +++ b/tests/tests.am @@ -50,8 +50,8 @@ TESTS += staticrootstest$(EXEEXT) check_PROGRAMS += staticrootstest staticrootstest_SOURCES = tests/staticrootstest.c staticrootstest_CFLAGS = -DSTATICROOTSLIB2 -staticrootstest_LDADD = $(test_ldadd) libstaticrootslib_test.la \ - libstaticrootslib2_test.la +staticrootstest_LDADD = $(nodist_libgc_la_OBJECTS) $(EXTRA_TEST_LIBS) \ + libstaticrootslib_test.la libstaticrootslib2_test.la check_LTLIBRARIES += libstaticrootslib_test.la libstaticrootslib2_test.la libstaticrootslib_test_la_SOURCES = tests/staticrootslib.c libstaticrootslib_test_la_LIBADD = $(test_ldadd) @@ -61,6 +61,9 @@ libstaticrootslib2_test_la_SOURCES = tests/staticrootslib.c libstaticrootslib2_test_la_LIBADD = $(test_ldadd) libstaticrootslib2_test_la_CFLAGS = -DSTATICROOTSLIB2 libstaticrootslib2_test_la_LDFLAGS = -no-undefined -rpath /nowhere +if ENABLE_SHARED +staticrootstest_LDADD += $(top_builddir)/libgc.la +endif if KEEP_BACK_PTRS TESTS += tracetest$(EXEEXT) @@ -106,7 +109,13 @@ test_cpp_SOURCES = tests/test_cpp.cc if AVOID_CPP_LIB test_cpp_LDADD = gc_cpp.o $(test_ldadd) $(CXXLIBS) else -test_cpp_LDADD = libgccpp.la $(test_ldadd) $(CXXLIBS) +test_cpp_LDADD = libgccpp.la $(nodist_libgc_la_OBJECTS) \ + $(EXTRA_TEST_LIBS) $(CXXLIBS) +## In case of static libraries build, libgc.a is already referenced in +## dependency_libs attribute of libgccpp.la file. +if ENABLE_SHARED +test_cpp_LDADD += $(top_builddir)/libgc.la +endif endif endif -- 2.7.4