From 7d2b9f3f3e24440ba3616ab62eb3ef112343c4c7 Mon Sep 17 00:00:00 2001 From: Sean Farrell Date: Sat, 4 Dec 2021 18:41:07 +0100 Subject: [PATCH] Fix Linux so/static build issue. Hardened linker do not like mixing shared and static libraries (who where compiled without -fPIC), thus simply build against the header only version if not shared library is available. --- .gitignore | 1 + example/CMakeLists.txt | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 1b452285..fbfedc8a 100644 --- a/.gitignore +++ b/.gitignore @@ -81,3 +81,4 @@ cmake-build-*/ *.tcl *.user *.sln +/output diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index f982f45b..d69ddeff 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -11,17 +11,22 @@ endif() # --------------------------------------------------------------------------------------- # Example of using shared libraries # --------------------------------------------------------------------------------------- -add_library(mylibrary SHARED mylibrary.cpp mylibrary.h) -target_link_libraries(mylibrary PRIVATE spdlog::spdlog) -target_compile_definitions(mylibrary PUBLIC SPDLOG_COMPILED_LIB) - -add_executable(library_example library_example.cpp) -target_link_libraries(library_example PRIVATE spdlog::spdlog mylibrary) -target_compile_definitions(library_example PUBLIC SPDLOG_COMPILED_LIB) - if(SPDLOG_BUILD_SHARED OR BUILD_SHARED_LIBS) + add_library(mylibrary SHARED mylibrary.cpp mylibrary.h) + target_link_libraries(mylibrary PRIVATE spdlog::spdlog) target_compile_definitions(mylibrary PUBLIC SPDLOG_SHARED_LIB) + target_compile_definitions(mylibrary PUBLIC SPDLOG_COMPILED_LIB) + + add_executable(library_example library_example.cpp) + target_link_libraries(library_example PRIVATE spdlog::spdlog mylibrary) target_compile_definitions(library_example PUBLIC SPDLOG_SHARED_LIB) + target_compile_definitions(library_example PUBLIC SPDLOG_COMPILED_LIB) +else() + add_library(mylibrary SHARED mylibrary.cpp mylibrary.h) + target_link_libraries(mylibrary PRIVATE spdlog::spdlog_header_only) + + add_executable(library_example library_example.cpp) + target_link_libraries(library_example PRIVATE spdlog::spdlog_header_only mylibrary) endif() # ---------------------------------------------------------------------------------------