summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2022-06-08 11:31:13 -0700
committerGitHub <noreply@github.com>2022-06-08 18:31:13 +0000
commitb76d2fb1e5bb839249b25b7094db94219695f515 (patch)
treeb69aa891816e5ef8be4aaf3ffdda48872b8e0692
parentb7a93cca37d2253ef36e4cc63ef38c3647404597 (diff)
downloadbinaryen-b76d2fb1e5bb839249b25b7094db94219695f515.tar.gz
binaryen-b76d2fb1e5bb839249b25b7094db94219695f515.tar.bz2
binaryen-b76d2fb1e5bb839249b25b7094db94219695f515.zip
Link shared library against thread libraries (#4715)
Also, add `-Wl,--no-undefined` when linking shared libraries. Adding this flags means we can better detect when libraries are missing from the `libbinaryen.so` link. In this case it reports undefined symbol for `pthread_create` (which is then addressed by this patch).
-rw-r--r--CMakeLists.txt5
1 files changed, 5 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 101985c99..ae5f38144 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -289,6 +289,10 @@ else()
# explicitly undefine it:
add_nondebug_compile_flag("-UNDEBUG")
endif()
+ if(NOT APPLE AND NOT "${CMAKE_CXX_FLAGS}" MATCHES "-fsanitize")
+ # This flag only applies to shared libraries so don't use add_link_flag
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
+ endif()
endif()
if(EMSCRIPTEN)
@@ -370,6 +374,7 @@ else()
message(STATUS "Building libbinaryen as shared library.")
add_library(binaryen SHARED ${binaryen_SOURCES} ${binaryen_objs})
endif()
+target_link_libraries(binaryen ${CMAKE_THREAD_LIBS_INIT})
if(NOT (BUILD_STATIC_LIB AND BYN_INSTALL_TOOLS_ONLY))
install(TARGETS binaryen
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}