Library not linked against libdl for multilib build on Linux

Issue #202 resolved
djcj created an issue

When using the script build/linux/multilib.sh to build a multilib version of x265, the resulting shared library uses symbols from libdl but isn't linked against it. This caused some problems when I tried to configure ffmpeg with libx265 enabled.

Afaik BSD-like systems don't have a separate libdl file so I guess this is a Linux-specific issue.

I recommend something like the following changes:

--- multilib.sh.orig    2015-10-17 16:22:20.088480771 +0200
+++ multilib.sh 2015-10-17 16:22:10.840480613 +0200
@@ -10,16 +10,21 @@
 cmake ../../../source -DHIGH_BIT_DEPTH=ON -DEXPORT_C_API=OFF -DENABLE_SHARED=OFF -DENABLE_CLI=OFF
 make ${MAKEFLAGS}

+uname=`uname`
+
 cd ../8bit
 ln -sf ../10bit/libx265.a libx265_main10.a
 ln -sf ../12bit/libx265.a libx265_main12.a
-cmake ../../../source -DEXTRA_LIB="x265_main10.a;x265_main12.a" -DEXTRA_LINK_FLAGS=-L. -DLINKED_10BIT=ON -DLINKED_12BIT=ON
+if [ "$uname" = "Linux" ]; then
+  # On Linux, we need to link against libdl
+  libdl=";-ldl"
+fi
+cmake ../../../source -DEXTRA_LIB="x265_main10.a;x265_main12.a$libdl" -DEXTRA_LINK_FLAGS=-L. -DLINKED_10BIT=ON -DLINKED_12BIT=ON
 make ${MAKEFLAGS}

 # rename the 8bit library, then combine all three into libx265.a
 mv libx265.a libx265_main.a

-uname=`uname`
 if [ "$uname" = "Linux" ]
 then

Comments (2)

  1. Sebastian Ramacher

    The shared objects are already linked with -ldl, but it's at the wrong place. The order of objects matters when linking. The following patch also fixes the issue:

    diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
    index 3da6865..dbb1af1 100644
    --- a/source/CMakeLists.txt
    +++ b/source/CMakeLists.txt
    @@ -455,6 +455,9 @@ option(ENABLE_SHARED "Build shared library" ON)
     if(ENABLE_SHARED)
         add_library(x265-shared SHARED "${PROJECT_BINARY_DIR}/x265.def" ${YASM_OBJS}
                     ${X265_RC_FILE} $<TARGET_OBJECTS:encoder> $<TARGET_OBJECTS:common>)
    +    if(EXTRA_LIB)
    +        target_link_libraries(x265-shared ${EXTRA_LIB})
    +    endif()
         target_link_libraries(x265-shared ${PLATFORM_LIBS})
         if(MSVC)
             set_target_properties(x265-shared PROPERTIES OUTPUT_NAME libx265)
    @@ -480,9 +483,6 @@ if(ENABLE_SHARED)
                     ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
                     RUNTIME DESTINATION ${BIN_INSTALL_DIR})
         endif()
    -    if(EXTRA_LIB)
    -        target_link_libraries(x265-shared ${EXTRA_LIB})
    -    endif()
         if(LINKER_OPTIONS)
             # set_target_properties can't do list expansion
             string(REPLACE ";" " " LINKER_OPTION_STR "${LINKER_OPTIONS}")
    

    It would also be nice if the code using dlopen wouldn't be built for the multilib build as it will never be used.

  2. Log in to comment