The ifdef guard that changes the definition of GPIOD_CXX_API between
"default" and "hidden" is there to prevent libraries that would include
gpiod.hpp from re-exporting libgpiodcxx symbols.
Unfortunately the hidden linkage only works for translation units within
the same ELF object. At static linking time we must always mark the
throwable types as visible or we'll get the following errors:
/usr/bin/ld: tests-chip.o:(.data+0x0): undefined reference to `typeinfo for gpiod::chip_closed'
/usr/bin/ld: tests-line-request.o:(.data+0x0): undefined reference to `typeinfo for gpiod::request_released'
/usr/bin/ld: .libs/gpiod-cxx-test: hidden symbol `_ZTIN5gpiod11chip_closedE' isn't defined
/usr/bin/ld: final link failed: bad value
On top of that we actually WANT to re-export typeinfo for throwable types
as they can be propagated to external callers when an exception is thrown.
The above error can only be triggered on clang. GCC seems to be
incorrectly omitting the "hidden" attribute in this case.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
libgpiodcxx_la_CXXFLAGS = -Wall -Wextra -g -std=gnu++17
libgpiodcxx_la_CXXFLAGS += -fvisibility=hidden -I$(top_srcdir)/include/
libgpiodcxx_la_CXXFLAGS += $(PROFILING_CFLAGS)
-libgpiodcxx_la_CXXFLAGS += -DGPIOD_CXX_BUILD
libgpiodcxx_la_LDFLAGS = -version-info $(subst .,:,$(ABI_CXX_VERSION))
libgpiodcxx_la_LDFLAGS += -lgpiod -L$(top_builddir)/lib
libgpiodcxx_la_LDFLAGS += $(PROFILING_LDFLAGS)
* the declarations in exception.hpp in order to expose the symbols of classes
* inheriting from standard exceptions.
*/
-#ifdef GPIOD_CXX_BUILD
#define GPIOD_CXX_API __attribute__((visibility("default")))
-#else
-#define GPIOD_CXX_API __attribute__((visibility("hidden")))
-#endif
#define __LIBGPIOD_GPIOD_CXX_INSIDE__
#include "gpiodcxx/chip.hpp"