From d8e23c1e932beeacd7433cd6aa9e2161d555254f Mon Sep 17 00:00:00 2001 From: Adrien Cassagne Date: Tue, 5 Mar 2024 15:57:04 +0100 Subject: [PATCH] Add 'POSITION_INDEPENDENT_CODE ON' (also known as '-fPIE'). (#99) First thx for these very useful lib! I encountered some issues when linking with `libcpptrace`. Typically, here is the error I got: ``` /usr/bin/ld: lib/cpptrace/lib/libcpptrace.a(cpptrace.cpp.o): relocation R_X86_64_32S against symbol `_ZTVNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEE@@GLIBCXX_3.4.21' can not be used when making a PIE object; recompile with -fPIE ``` I just added the `POSITION_INDEPENDENT_CODE ON` flag on the targets, and now it works like a charm :-). --- CMakeLists.txt | 1 + README.md | 1 + cmake/OptionVariables.cmake | 1 + 3 files changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 317177d..851c1e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -267,6 +267,7 @@ set_target_properties( SOVERSION "${PROJECT_VERSION_MAJOR}" EXPORT_NAME "cpptrace" OUTPUT_NAME "cpptrace" + POSITION_INDEPENDENT_CODE ${CPPTRACE_POSITION_INDEPENDENT_CODE} ) # Header files generated by CMake diff --git a/README.md b/README.md index 66b7c11..ccfb0ed 100644 --- a/README.md +++ b/README.md @@ -898,6 +898,7 @@ Other useful configurations: the fault of your project. Defaults to On. - `CPPTRACE_INSTALL_CMAKEDIR`: Override for the installation path for the cmake configs. - `CPPTRACE_USE_EXTERNAL_LIBDWARF=On/Off`: Get libdwarf from `find_package` rather than `FetchContent`. +- `CPPTRACE_POSITION_INDEPENDENT_CODE=On/Off`: Compile the library as a position independent code (PIE). Defaults to On. Testing: - `CPPTRACE_BUILD_TESTING` Build small demo and test program diff --git a/cmake/OptionVariables.cmake b/cmake/OptionVariables.cmake index 022bfd8..5589a8d 100644 --- a/cmake/OptionVariables.cmake +++ b/cmake/OptionVariables.cmake @@ -164,6 +164,7 @@ option(CPPTRACE_CONAN "" OFF) option(CPPTRACE_VCPKG "" OFF) option(CPPTRACE_SANITIZER_BUILD "" OFF) option(CPPTRACE_WERROR_BUILD "" OFF) +option(CPPTRACE_POSITION_INDEPENDENT_CODE "" ON) mark_as_advanced( CPPTRACE_BACKTRACE_PATH