From 0638c5600fcb6e34912ee55ad21efbdc18b15c13 Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Fri, 17 Oct 2025 23:42:00 +0200 Subject: [PATCH 1/2] Fix problem with linking on Linux using static library and relocation problems in the code. In order to be able to link on Linux to other shared libraries, while compiling e.g. a static webui library, the -fPIC is necessary. This has been tested on Linux. Signed-off-by: Hans Dijkema --- CMakeLists.txt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 119440982..5e199eff1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,22 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) + +# In order to be able to link on Linux to other shared libraries, +# while compiling e.g. a static webui library, the -fPIC +# is necessary. This has been tested on Linux. +if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + # using Clang + add_compile_options(-fPIC) +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # using GCC + add_compile_options(-fPIC) +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + # using Intel C++ +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # using Visual Studio C++ +endif() + # Variables for library names, source files, etc. set(WEBUI_DEFAULT_OUT_LIB_NAME "webui-2") @@ -118,4 +134,4 @@ if (WEBUI_BUILD_EXAMPLES) if (MSVC) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT call_js_from_cpp) endif() -endif() \ No newline at end of file +endif() From 47e20e357764575e2da24cbde3777582b4087bad Mon Sep 17 00:00:00 2001 From: Showns <116365846+AlbertShown@users.noreply.github.com> Date: Mon, 20 Oct 2025 15:48:44 -0400 Subject: [PATCH 2/2] Clarify fPIC requirement for linking shared libraries Updated comment for clarity on linking shared libraries. --- CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e199eff1..1ff122e4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,9 +13,7 @@ set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) -# In order to be able to link on Linux to other shared libraries, -# while compiling e.g. a static webui library, the -fPIC -# is necessary. This has been tested on Linux. +# In order to be able to link with other shared libraries on Linux we may need `-fPIC`. if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # using Clang add_compile_options(-fPIC)