Skip to content

Commit 0638c56

Browse files
committed
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 <hans@dijkewijk.nl>
1 parent 80f8976 commit 0638c56

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
1212
set(CMAKE_C_STANDARD 99)
1313
set(CMAKE_C_STANDARD_REQUIRED ON)
1414

15+
16+
# In order to be able to link on Linux to other shared libraries,
17+
# while compiling e.g. a static webui library, the -fPIC
18+
# is necessary. This has been tested on Linux.
19+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
20+
# using Clang
21+
add_compile_options(-fPIC)
22+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
23+
# using GCC
24+
add_compile_options(-fPIC)
25+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
26+
# using Intel C++
27+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
28+
# using Visual Studio C++
29+
endif()
30+
1531
# Variables for library names, source files, etc.
1632
set(WEBUI_DEFAULT_OUT_LIB_NAME "webui-2")
1733

@@ -118,4 +134,4 @@ if (WEBUI_BUILD_EXAMPLES)
118134
if (MSVC)
119135
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT call_js_from_cpp)
120136
endif()
121-
endif()
137+
endif()

0 commit comments

Comments
 (0)