From 28b0d321a39c510f0bb4a06d895bcfc89bfbf7eb Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Fri, 22 Apr 2022 22:58:32 +0200 Subject: [PATCH] Enable -fPIC to fix linking static libraries when building with Qt6 Otherwise the build would fail: /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: ../lib/libkonsoleprivate_core.a(ShellCommand.cpp.o): warning: relocation against `_ZN7QString6_emptyE@@Qt_6' in read-only section `.text' /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: ../lib/libkonsoleprivate_core.a(ShellCommand.cpp.o): relocation R_X86_64_PC32 against symbol `_ZN10QByteArray6_emptyE@@Qt_6' can not be used when making a shared object; recompile with -fPIC /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: final link failed: bad value This seems to affect both STATIC and OBJECT CMake library types. --- src/CMakeLists.txt | 3 +++ src/colorscheme/CMakeLists.txt | 3 +++ src/decoders/CMakeLists.txt | 2 ++ src/keyboardtranslator/CMakeLists.txt | 2 ++ src/profile/CMakeLists.txt | 2 ++ src/session/CMakeLists.txt | 3 +++ 6 files changed, 15 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f11f6e35..70e9d2cc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -89,6 +89,8 @@ ecm_qt_declare_logging_category( ) add_library(konsoleprivate_core STATIC ${konsoleprivate_core_SRCS}) +# Needed to link this static lib to shared libs +set_target_properties(konsoleprivate_core PROPERTIES POSITION_INDEPENDENT_CODE ON) target_link_libraries(konsoleprivate_core ${konsole_LIBS}) set(konsolehelpers_SRCS @@ -98,6 +100,7 @@ add_library(konsolehelpers STATIC ${konsolehelpers_SRCS} ) +set_target_properties(konsolehelpers PROPERTIES POSITION_INDEPENDENT_CODE ON) target_link_libraries(konsolehelpers Qt::Core Qt::Widgets diff --git a/src/colorscheme/CMakeLists.txt b/src/colorscheme/CMakeLists.txt index 3dca845f..34824701 100644 --- a/src/colorscheme/CMakeLists.txt +++ b/src/colorscheme/CMakeLists.txt @@ -26,6 +26,9 @@ add_library(konsolecolorscheme STATIC ${konsole_colorscheme_SRCS} ) +# Needed to link this static lib to shared libs +set_target_properties(konsolecolorscheme PROPERTIES POSITION_INDEPENDENT_CODE ON) + generate_export_header(konsolecolorscheme BASE_NAME konsolecolorscheme) target_include_directories(konsolecolorscheme PUBLIC ${CMAKE_CURRENT_BINARY_DIR} diff --git a/src/decoders/CMakeLists.txt b/src/decoders/CMakeLists.txt index 9f445af1..3a03944a 100644 --- a/src/decoders/CMakeLists.txt +++ b/src/decoders/CMakeLists.txt @@ -4,6 +4,8 @@ add_library(konsoledecoders PlainTextDecoder.cpp HTMLDecoder.cpp ) + +set_target_properties(konsoledecoders PROPERTIES POSITION_INDEPENDENT_CODE ON) generate_export_header(konsoledecoders BASE_NAME konsoledecoders) target_include_directories(konsoledecoders PUBLIC ${CMAKE_CURRENT_BINARY_DIR} diff --git a/src/keyboardtranslator/CMakeLists.txt b/src/keyboardtranslator/CMakeLists.txt index 812d5c58..5403138c 100644 --- a/src/keyboardtranslator/CMakeLists.txt +++ b/src/keyboardtranslator/CMakeLists.txt @@ -6,6 +6,8 @@ add_library(keyboardtranslator KeyboardTranslator.cpp KeyboardTranslatorReader.cpp ) +# Needed to link this static lib to shared libs +set_target_properties(keyboardtranslator PROPERTIES POSITION_INDEPENDENT_CODE ON) target_link_libraries( keyboardtranslator diff --git a/src/profile/CMakeLists.txt b/src/profile/CMakeLists.txt index 34fb583b..b8c8bf1a 100644 --- a/src/profile/CMakeLists.txt +++ b/src/profile/CMakeLists.txt @@ -12,6 +12,8 @@ OBJECT ProfileModel.cpp ${konsoleprofile_SRCS} ) +set_property(TARGET konsoleprofile PROPERTY POSITION_INDEPENDENT_CODE ON) + generate_export_header(konsoleprofile BASE_NAME konsoleprofile) target_include_directories(konsoleprofile PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries( diff --git a/src/session/CMakeLists.txt b/src/session/CMakeLists.txt index e6bb6ec1..3cfcca39 100644 --- a/src/session/CMakeLists.txt +++ b/src/session/CMakeLists.txt @@ -30,6 +30,9 @@ add_library(konsolesession OBJECT ${konsole_session_SRCS} ) + +set_property(TARGET konsolesession PROPERTY POSITION_INDEPENDENT_CODE ON) + generate_export_header(konsolesession BASE_NAME konsolesession) target_include_directories(konsolesession PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(