Srt: [BUG] Linux: static linking apps fails

Created on 9 Mar 2020  ·  24Comments  ·  Source: Haivision/srt

Background
I'm building libsrt on Ubuntu 16.04.
I'm building in a Docker build process, since it gives me a clean and easily reproducible build environment - but this should be irrelevant to this bug report.
I've been building FFmpeg in this way without libsrt for years - adding libsrt has been this weekend's challenge.
I'm building for linux x86_64 and also cross compiling for win_x86_64 and osx_x86_64 - which
My final goal is to build a static FFmpeg for all three platforms including libsrt.

Describe the bug
I've built OpenSSL 1.0.2 as static from git branch OpenSSL_1_0_2-stable.

I wand to build libsrt as static, but after make has built libsrt.a it builds some applications, and those do not link correctly (they need -ldl appending to the link command).

cmake \
    -G \"Unix Makefiles\" \
    -DCMAKE_INSTALL_PREFIX=${prefix} \
    -DENABLE_C_DEPS=ON \
    -DENABLE_SHARED=OFF \
    -DENABLE_STATIC=ON
make VERBOSE=1
[ 91%] Linking CXX executable srt-live-transmit
/usr/bin/cmake -E cmake_link_script CMakeFiles/srt-live-transmit.dir/link.txt --verbose=1
/usr/bin/g++   --static -static -I/opt/ffbuild/include    -DENABLE_LOGGING=1 -Wall -Wextra -O3 -DNDEBUG   -L/opt/ffbuild/lib -static CMakeFiles/srt-live-transmit.dir/apps/srt-live-transmit.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/apputil.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/logsupport.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/socketoptions.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/transmitmedia.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/uriparser.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/verbose.cpp.o  -o srt-live-transmit -rdynamic libsrt.a -ldl -Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -lpthread 
/opt/ffbuild/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x11): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x24): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x2f): undefined reference to `dlclose'
/opt/ffbuild/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x334): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x3db): undefined reference to `dlerror'
/opt/ffbuild/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
dso_dlfcn.c:(.text+0x454): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x4fb): undefined reference to `dlerror'
/opt/ffbuild/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x569): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x5cb): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x603): undefined reference to `dlerror'
/opt/ffbuild/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x69f): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0x709): undefined reference to `dlerror'
/opt/ffbuild/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x762): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
make[2]: *** [srt-live-transmit] Error 1
CMakeFiles/srt-live-transmit.dir/build.make:109: recipe for target 'srt-live-transmit' failed
make[2]: Leaving directory '/opt/ffbuild/src/srt/build'
CMakeFiles/Makefile2:105: recipe for target 'CMakeFiles/srt-live-transmit.dir/all' failed
make[1]: Leaving directory '/opt/ffbuild/src/srt/build'
Makefile:127: recipe for target 'all' failed
make[1]: *** [CMakeFiles/srt-live-transmit.dir/all] Error 2
make: *** [all] Error 2

Workaround
Since I only want libsrt.a I can work around by installing the required component (libsrt.a, srt.pc and various .h files) - but it's a bit ugly.

make VERBOSE=1 srt_static \
 && mkdir -p ${prefix}/include/srt/win \
 && install -m 644 -c libsrt.a ${prefix}/lib/libsrt.a \
 && install -m 644 -c srt.pc ${prefix}/lib/pkgconfig/srt.pc \
 && install -m 644 -c version.h ${prefix}/include/srt/version.h \
 && install -m 644 -c ../srtcore/srt.h ${prefix}/include/srt/srt.h \
 && install -m 644 -c ../srtcore/platform_sys.h ${prefix}/include/srt/platform_sys.h \
 && install -m 644 -c ../srtcore/srt4udt.h ${prefix}/include/srt/srt4udt.h \
 && install -m 644 -c ../srtcore/logging_api.h ${prefix}/include/srt/logging_api.h

(plus some other .h files if I'm cross-compiling for Windows)

Bug [build]

Most helpful comment

Ok, I think I got it. I manually changed the libcrypto.pc from above, as:

Libs: -L${libdir} -lcrypto -lz -ldl

thus showing the _private_ libs as _public_ libs, and it worked!

This is NOT the right way to do this, but I think it clearly shows the config/cmake process is not picking up the _static_ (i.e. private) internal libs when it is finding OpenSSL. Coming through FFMPEG configure, it is clear they pass --static and append the Libs.Private when necessary.

I'm way way over my head now. Thanks for listening :)

All 24 comments

I've checked the latest master with the following command, and it worked:

cmake ../ -DENABLE_SHARED=OFF -DENABLE_STATIC=ON

So it looks like something around linking static OpenSSL 🤔
Are you sure you don't mix paths to shared and static OpenSSL builds?

Stating from the error reports, it's a problem reported for the OpenSSL library, not for SRT. Adding -ldl option to linker should help, but this should have been reported by pkg-config --libs for OpenSSL in the first place - you might want to check this thing on OpenSSL.

As a workaround, there's a build option you can use in SRT - for cmake it will be WITH_EXTRALIBS. If you pass -DWITH_EXTRALIBS=-ldl, it should work.

Closing as resolved.
@himslm01 Please don't hesitate to reopen if you disagree with the proposed solution.

FWIW I am still unable to build static. Ubuntu (various versions), using this build script for a truly "isolated" build:

https://github.com/markus-perl/ffmpeg-build-script

It seems to work fine on macOS. I've used the script for a while and know that it works fine without the SRT build (tested today). I let it build it past openssl and then try to do the SRT build before ffmpeg:

        git clone https://github.com/Haivision/srt.git
        cd srt
        git checkout 10ed37b6d4b49a3042213b029f0de6bca4bcfe83
        cmake -DCMAKE_INSTALL_PREFIX:PATH="${WORKSPACE}" -DENABLE_SHARED=OFF -DENABLE_STATIC=ON -DENABLE_APPS=ON -DWITH_EXTRALIBS=-ldl .
        execute make -j $MJOBS
        execute make install
        build_done "srt"

(Using the older commit hash here because of the ffmpeg issue with deprecated calls. The results are the same from what I can tell with both HEAD and 1.4.1)

Always the same issue of srt-live-transmit failing to link because libcrypto is trying to find libz.so; if I manually specific the libz.a lib in the link.txt for srt-live-transmit, then I can get a bit further but the next app fails similarly.

I've tried every combination of ldl and static and FLAGS and can't seem to make it work. I would love any insight. :) I don't want to report on the build script because it builds a perfectly fine static binary w/o SRT, so I feel like the issue is on this side, or something I'm just not getting. Willing to try whatever you need :) Thanks for any and all help...SRT is amazing and really saved me already to reliably do some streaming in really bad conditions!

Example result:

...
building openssl
=======================
Downloading https://www.openssl.org/source/openssl-1.1.1g.tar.gz
... Done
$ ./config --prefix=/root/ffmpeg-build-script/workspace --openssldir=/root/ffmpeg-build-script/workspace --with-zlib-include=/root/ffmpeg-build-script/workspace/include/ --with-zlib-lib=/root/ffmpeg-build-script/workspace/lib no-shared zlib
$ make -j 1
$ make install

building srt
=======================
Cloning into 'srt'...
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 8587 (delta 0), reused 0 (delta 0), pack-reused 8586
Receiving objects: 100% (8587/8587), 9.81 MiB | 27.60 MiB/s, done.
Resolving deltas: 100% (6694/6694), done.
Note: checking out '10ed37b6d4b49a3042213b029f0de6bca4bcfe83'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 10ed37b Merge pull request #1373 from ethouris/dev-fix-compiler-standard-old
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /root/ffmpeg-build-script/workspace/bin/pkg-config (found version "0.29.2")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- BUILD TYPE: Release
-- LOGGING: ENABLED
-- USE_BUSY_WAITING: OFF (default)
-- No WITH_COMPILER_PREFIX - using C++ compiler /usr/bin/c++
-- Looking for inet_pton
-- Looking for inet_pton - found
-- Checking for module 'openssl libcrypto'
--   Found openssl libcrypto, version 1.1.1g;1.1.1g
-- SSL via pkg-config: -L /root/ffmpeg-build-script/workspace/lib -I /root/ffmpeg-build-script/workspace/include -l;ssl;crypto
-- ENCRYPTION: ENABLED, using: openssl libcrypto
-- SSL libraries: ssl;crypto
-- COMPILER: GNU (/usr/bin/c++) - GNU compat
-- NOTE: GNU 7.5.0 - assuming default C++11.
-- STDCXX_SYNC: OFF
-- DETECTED SYSTEM: LINUX;  LINUX=1
-- APP: srt_virtual: using default C++ standard
-- ADDING TRANSITIVE LINK DEP to:srt_static : -lpthread
-- INSTALL DIRS: bin=bin lib=lib shlib=lib include=include
-- APPS: ENABLED, std=
-- APP: srtsupport_virtual: using default C++ standard
-- APP: srt-live-transmit: using default C++ standard
-- APP: srt-file-transmit: using default C++ standard
-- APP: srt-tunnel: using default C++ standard
-- DEVEL APPS (testing): DISABLED
-- Configuring done
-- Generating done
-- Build files have been written to: /root/ffmpeg-build-script/packages/srt
$ make -j 1
Scanning dependencies of target srtsupport_virtual
[  2%] Building CXX object CMakeFiles/srtsupport_virtual.dir/apps/apputil.cpp.o
[  4%] Building CXX object CMakeFiles/srtsupport_virtual.dir/apps/logsupport.cpp.o
[  6%] Building CXX object CMakeFiles/srtsupport_virtual.dir/apps/socketoptions.cpp.o
[  8%] Building CXX object CMakeFiles/srtsupport_virtual.dir/apps/transmitmedia.cpp.o
[ 11%] Building CXX object CMakeFiles/srtsupport_virtual.dir/apps/uriparser.cpp.o
[ 13%] Building CXX object CMakeFiles/srtsupport_virtual.dir/apps/verbose.cpp.o
[ 13%] Built target srtsupport_virtual
Scanning dependencies of target srt_virtual
[ 15%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/api.cpp.o
[ 17%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/buffer.cpp.o
[ 20%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/cache.cpp.o
[ 22%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/channel.cpp.o
[ 24%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/common.cpp.o
[ 26%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/core.cpp.o
[ 28%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/crypto.cpp.o
[ 31%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/epoll.cpp.o
[ 33%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/fec.cpp.o
[ 35%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/handshake.cpp.o
[ 37%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/list.cpp.o
[ 40%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/md5.cpp.o
[ 42%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/packet.cpp.o
[ 44%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/packetfilter.cpp.o
[ 46%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/queue.cpp.o
[ 48%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/congctl.cpp.o
[ 51%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/srt_c_api.cpp.o
[ 53%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/window.cpp.o
[ 55%] Building C object CMakeFiles/srt_virtual.dir/srtcore/srt_compat.c.o
[ 57%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/sync.cpp.o
[ 60%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/sync_cxx11.cpp.o
[ 62%] Building C object CMakeFiles/srt_virtual.dir/haicrypt/cryspr.c.o
[ 64%] Building C object CMakeFiles/srt_virtual.dir/haicrypt/cryspr-openssl.c.o
[ 66%] Building C object CMakeFiles/srt_virtual.dir/haicrypt/hcrypt.c.o
[ 68%] Building C object CMakeFiles/srt_virtual.dir/haicrypt/hcrypt_ctx_rx.c.o
[ 71%] Building C object CMakeFiles/srt_virtual.dir/haicrypt/hcrypt_ctx_tx.c.o
[ 73%] Building C object CMakeFiles/srt_virtual.dir/haicrypt/hcrypt_rx.c.o
[ 75%] Building C object CMakeFiles/srt_virtual.dir/haicrypt/hcrypt_sa.c.o
[ 77%] Building C object CMakeFiles/srt_virtual.dir/haicrypt/hcrypt_tx.c.o
[ 80%] Building C object CMakeFiles/srt_virtual.dir/haicrypt/hcrypt_xpt_srt.c.o
[ 82%] Building CXX object CMakeFiles/srt_virtual.dir/haicrypt/haicrypt_log.cpp.o
[ 82%] Built target srt_virtual
Scanning dependencies of target srt_static
[ 84%] Building C object CMakeFiles/srt_static.dir/cmake_object_lib_support.c.o
[ 86%] Linking CXX static library libsrt.a
[ 86%] Built target srt_static
Scanning dependencies of target srt-live-transmit
[ 88%] Building CXX object CMakeFiles/srt-live-transmit.dir/apps/srt-live-transmit.cpp.o
[ 91%] Linking CXX executable srt-live-transmit
/root/ffmpeg-build-script/workspace/lib/libcrypto.a(c_zlib.o): In function `zlib_stateful_expand_block':
c_zlib.c:(.text+0x3b): undefined reference to `inflate'
/root/ffmpeg-build-script/workspace/lib/libcrypto.a(c_zlib.o): In function `zlib_stateful_compress_block':
c_zlib.c:(.text+0xa4): undefined reference to `deflate'
/root/ffmpeg-build-script/workspace/lib/libcrypto.a(c_zlib.o): In function `zlib_stateful_finish':
c_zlib.c:(.text+0xd9): undefined reference to `inflateEnd'
c_zlib.c:(.text+0xe2): undefined reference to `deflateEnd'
/root/ffmpeg-build-script/workspace/lib/libcrypto.a(c_zlib.o): In function `zlib_stateful_init':
c_zlib.c:(.text+0x1a8): undefined reference to `inflateInit_'
c_zlib.c:(.text+0x21a): undefined reference to `deflateInit_'
/root/ffmpeg-build-script/workspace/lib/libcrypto.a(c_zlib.o): In function `bio_zlib_ctrl':
c_zlib.c:(.text+0x324): undefined reference to `zError'
c_zlib.c:(.text+0x44c): undefined reference to `deflate'
/root/ffmpeg-build-script/workspace/lib/libcrypto.a(c_zlib.o): In function `bio_zlib_write':
c_zlib.c:(.text+0x730): undefined reference to `deflate'
c_zlib.c:(.text+0x7ec): undefined reference to `zError'
c_zlib.c:(.text+0x85f): undefined reference to `deflateInit_'
/root/ffmpeg-build-script/workspace/lib/libcrypto.a(c_zlib.o): In function `bio_zlib_read':
c_zlib.c:(.text+0x948): undefined reference to `inflate'
c_zlib.c:(.text+0x9c4): undefined reference to `zError'
c_zlib.c:(.text+0xa45): undefined reference to `inflateInit_'
/root/ffmpeg-build-script/workspace/lib/libcrypto.a(c_zlib.o): In function `bio_zlib_free':
c_zlib.c:(.text+0xab5): undefined reference to `inflateEnd'
c_zlib.c:(.text+0xae0): undefined reference to `deflateEnd'
/root/ffmpeg-build-script/workspace/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x11): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x24): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x2f): undefined reference to `dlclose'
/root/ffmpeg-build-script/workspace/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x1c4): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x282): undefined reference to `dlerror'
/root/ffmpeg-build-script/workspace/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x2f1): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x369): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x3a5): undefined reference to `dlerror'
/root/ffmpeg-build-script/workspace/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x471): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0x4d6): undefined reference to `dlerror'
/root/ffmpeg-build-script/workspace/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x6b2): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
CMakeFiles/srt-live-transmit.dir/build.make:96: recipe for target 'srt-live-transmit' failed
make[2]: *** [srt-live-transmit] Error 1
CMakeFiles/Makefile2:81: recipe for target 'CMakeFiles/srt-live-transmit.dir/all' failed
make[1]: *** [CMakeFiles/srt-live-transmit.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

@rtgoodwin
It is likely something to do with OpenSSL build, as in your case it seems to require further dependencies that SRT is not aware of.

Here is where SRT found OpenSSL:

-- SSL via pkg-config: -L /root/ffmpeg-build-script/workspace/lib -I /root/ffmpeg-build-script/workspace/include -l;ssl;crypto
-- ENCRYPTION: ENABLED, using: openssl libcrypto
-- SSL libraries: ssl;crypto

Then it is OpenSSL that expects other libraies to be included.

@ethouris provided a good suggestion on how to specify extra libs:

As a workaround, there's a build option you can use in SRT - for cmake it will be WITH_EXTRALIBS. If you pass -DWITH_EXTRALIBS=-ldl, it should work.

As I can see, the script builds OpenSSL, so it has to provide additional library dependencies of OpenSSL if needed (--with-zlib-lib="${WORKSPACE}"/lib no-shared zlib):

if build "openssl"; then
    download "https://www.openssl.org/source/openssl-1.1.1g.tar.gz" "openssl-1.1.1g.tar.gz"
    cd "$PACKAGES"/openssl-1.1.1g || exit
    execute ./config --prefix="${WORKSPACE}" --openssldir="${WORKSPACE}" --with-zlib-include="${WORKSPACE}"/include/ --with-zlib-lib="${WORKSPACE}"/lib no-shared zlib
    execute make -j $MJOBS
    execute make install
    build_done "openssl"
fi

@maxsharabayko Thanks for the quick reply! As you can see in my paste above, I am already passing WITH_EXTRA_LIBS. I will do some more research to see how to link zlib into OpenSSL; it is already being done so with the “zlib” switch to “use” zlib, and that is the ‘not dynamic’ version of the switch from what I read. I don’t know that it is meant to truly statically link by default, rather incorporating the library for its own use possibly; it’s just not clear. But perhaps there is some rarely used method, or way to force the lib to be bundled afterwards. I will indeed report back one way or the other. :) For the time being, simply turning off apps accomplishes what is needed as only (I believe) libsrt is actually needed from ffmpeg side, but I’d feel much better if the whole package worked. :) Thank you again!

As you can see in my paste above, I am already passing WITH_EXTRA_LIBS.

Might be that you should also add zlib to the list of exrta libs, not only dl.

@maxsharabayko Sadly no success, tried:

With this last one, for example:
LIBS="-lz -ldl" cmake -DENABLE_APPS=ON -DENABLE_SHARED=OFF -DSSL_INCLUDE_DIRS=${WORKSPACE}/include -DSSL_LIBRARY_DIRS=${WORKSPACE}/lib -DCMAKE_INSTALL_PREFIX:PATH="${WORKSPACE}" -DWITH_EXTRALIBS="-lz -ldl"

then CMakeFiles/srt-live-transmit/link.txt (first to fail) ends up like:

/usr/bin/c++     -DENABLE_LOGGING=1 -Wall -Wextra -O3 -DNDEBUG   -lz -ldl -rdynamic CMakeFiles/srt-live-transmit.dir/apps/srt-live-transmit.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/apputil.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/logsupport.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/socketoptions.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/transmitmedia.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/uriparser.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/verbose.cpp.o  -o srt-live-transmit  -L/root/ffmpeg-build-script/workspace/lib -Wl,-rpath,/root/ffmpeg-build-script/workspace/lib: libsrt.a -ldl -lssl -lcrypto -lpthread

If I manually change it to (note the very end):

/usr/bin/c++     -DENABLE_LOGGING=1 -Wall -Wextra -O3 -DNDEBUG   -lz -ldl -rdynamic CMakeFiles/srt-live-transmit.dir/apps/srt-live-transmit.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/apputil.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/logsupport.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/socketoptions.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/transmitmedia.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/uriparser.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/verbose.cpp.o  -o srt-live-transmit  -L/root/ffmpeg-build-script/workspace/lib -Wl,-rpath,/root/ffmpeg-build-script/workspace/lib: libsrt.a -lssl -lcrypto -lz -ldl -lpthread

it works, then goes on to tunnel which fails for the same reason.

I did try outfitting the openssl build with all the flags I could think of:

export LIBS="-lz -ldl" echo "LIBS IS" "$LIBS" execute ./config --prefix="${WORKSPACE}" --openssldir="${WORKSPACE}" --with-zlib-include="${WORKSPACE}"/include/ -DWITH_EXTRALIBS="-lz -ldl" --with-zlib-lib="${WORKSPACE}"/lib no-shared zlib

So, the best I can say, without knowing why, is that somehow in the configure/cmake, -lz isn't included, and -ldl isn't _after_ the other libs, which I've read it's supposed to be. (Again, not entirely clear why, except that dependencies should follow each other.)

I don't know if that gives you any more guidance...I hope so? :) Since it's pointing to exactly where it's failing and what fixes it? I'm out of ideas and don't want to waste more of your time if not, and/or if I should go back to looking at the way openssl itself builds.

Thanks!

Weird. The -DWITH_EXTRALIBS is used here to set the CMAKE_EXE_LINKER_FLAGS.
What is the version of your CMake?
Might be worth adding WITH_EXTRALIBS totarget_link_libraries somewhere here instead:

target_link_libraries(${name} ${srt_link_library} ${WITH_EXTRALIBS})

Looks like the version is cmake-3.15.4 (somewhat old? not sure why this version TBH...I'm guessing there is a reason, and/or a pain to move to a new one, but I'll look into it.)

With that patch to CmakeLists, the link.txt:

/usr/bin/c++     -DENABLE_LOGGING=1 -Wall -Wextra -O3 -DNDEBUG   -lz -ldl -rdynamic CMakeFiles/srt-live-transmit.dir/apps/srt-live-transmit.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/apputil.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/logsupport.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/socketoptions.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/transmitmedia.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/uriparser.cpp.o CMakeFiles/srtsupport_virtual.dir/apps/verbose.cpp.o  -o srt-live-transmit  -L/root/ffmpeg-build-script/workspace/lib -Wl,-rpath,/root/ffmpeg-build-script/workspace/lib: libsrt.a -lz -ldl -ldl -lssl -lcrypto -lpthread

So -lz -ldl are both present, but wrong ordering.

I boldly tried hacking by putting zlib into the openssl.pc package config, same issue. Officially out of ideas :)

The script is very solid and portable if you want to try it on a machine. i'm happy to even provide you a clean VM if you would like?

I would like to have this solved for everyone but technically my use case (ffmpeg receiving srt, copy into rtmp outbound stream) seems to be solved by libsrt without the "apps" being built?

For now, this VERY UGLY hack works, after cmake ;) Will try new ver of cmake, and offer to provide an Ubuntu instance stands!

sed -i -e 's/libsrt.a -ldl -lssl -lcrypto -lpthread/libsrt.a -lssl -lcrypto -lz -ldl -lpthread/' CMakeFiles/srt-live-transmit.dir/link.txt
sed -i -e 's/libsrt.a -ldl -lssl -lcrypto -lpthread/libsrt.a -lssl -lcrypto -lz -ldl -lpthread/' CMakeFiles/srt-tunnel.dir/link.txt
sed -i -e 's/libsrt.a -ldl -lssl -lcrypto -lpthread/libsrt.a -lssl -lcrypto -lz -ldl -lpthread/' CMakeFiles/srt-file-transmit.dir/link.txt

Never reported back; Cmake version didn't make a difference.

Well, still just about to give up, but noticed this:
CMakeCache.txt:SSL_STATIC_LDFLAGS:INTERNAL=-L/root/ffmpeg-build-script/workspace/lib;-lssl;-lcrypto;-lz;-ldl;-pthread

So clearly the dependencies are being picked up; however they are not passed to the Apps in the linking as we see, both in the link.txt files and I think here:

-- SSL via pkg-config: -L /root/ffmpeg-build-script/workspace/lib -I /root/ffmpeg-build-script/workspace/include -l;ssl;crypto
-- ENCRYPTION: ENABLED, using: openssl libcrypto

The libcrypto.pc does indicate that these libs are compiled in as private:

root@relaytest:~/ffmpeg-build-script/packages/srt# cat ../../workspace/lib/pkgconfig/libcrypto.pc
prefix=/root/ffmpeg-build-script/workspace
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
enginesdir=${libdir}/engines-1.1

Name: OpenSSL-libcrypto
Description: OpenSSL cryptography library
Version: 1.1.1g
Libs: -L${libdir} -lcrypto
Libs.private: -lz -ldl -pthread
Cflags: -I${includedir}

I did read a bit about how you MUST manually call out linking for additional compiled in libs, and that you MUST indicate you are requesting the STATIC libs info from pkg-config. So this all seems to suggest openssl is compiled properly (and ffmpeg can compile against it just fine).

I can't tell which is happening and which isn't; and I don't know what SSL_STATIC_LDFLAGS:INTERNAL is, and/or why it isn't being used when it seems like exactly what is needed.

Giving _for today_ anyway :) Maybe I gave a further hint.

Ok, I think I got it. I manually changed the libcrypto.pc from above, as:

Libs: -L${libdir} -lcrypto -lz -ldl

thus showing the _private_ libs as _public_ libs, and it worked!

This is NOT the right way to do this, but I think it clearly shows the config/cmake process is not picking up the _static_ (i.e. private) internal libs when it is finding OpenSSL. Coming through FFMPEG configure, it is clear they pass --static and append the Libs.Private when necessary.

I'm way way over my head now. Thanks for listening :)

@maxsharabayko does this count as a bug for you, since it resolves the issue? Do you need me to open a new one or anything?

Edit: Sorry I forgot to note the fix was by adding _STATIC SSL vars when necessary to the CMakeLists as noted here: https://cmake.org/cmake/help/v3.5/module/FindPkgConfig.html . Of course this works with PkgConfig only but I don't know if that really in fact covers the most likely scenarios. Example where OPENSSL_LIBRARIES (or possibly SSL_LIBRARIES) in general are used, also include _LIBRARIES_STATIC. Specifically here I believe: https://github.com/Haivision/srt/blob/333d34faf66b8f73f0647767086fa7552353dc1c/CMakeLists.txt#L324

Hi @rtgoodwin
It looks like something to be iproved in our CMake, but still I can't say I got the problem 100%.
OpenSSL is linked statically, and it needs zlib to be linked as well. But it is marked as a private dependency in OpenSSL's CmakeLists.txt, right?
Can cmake know this on its own, or do we need to fix/improve the -DWITH_EXTRALIBS to have the correct order of dependent libraries?

Sorry we commented at same time :) See new edit above. I don't know Cmake well enough but I think it's basically a check of "if we are asked to build static, then also include this extra variable".

BTW I think this isn't specific to openssl/zlib, this could be true in other cases, but certainly for SRT + openssl static + statically compiled ZLIB it is true. Reading the Cmake doc is what made it jump out to me, the fact that it automatically creates the _STATIC variables for use if needed.

Let me reopen this issue to consider in the future then.
It will still require some research to see if SRT's CMake can/should detect extra dependencies of OpenSSL or any other statically built library.

Summary

When OpenSSL is built statically, building SRT apps fails, as there is an additional dependency zlib that has to be linked. Specifying zlib in -DWITH_EXTRALIBS does not help due to the wrong order (zlib is included before OpenSSL?).

Steps to reproduce

Not clear. Try to link statically built OpenSSL?
Or follow ffmpeg-build-script.

Actually the more I think on it, I don't think it is an issue to just add to that line the OPENSSL_LIBRARIES_STATIC anyway, as you are already in a pkg-config conditional and there is no harm in passing those libraries to the linker? They would not be used if not needed I think? I am not a C developer so I could be very wrong.

Edit: I see you reopened, thanks! I don't think WITH_EXTRA should be needed if Cmake and pkg-config itself provides the detection as indicated. (For non pkg-config, truly I don't know.)

Edit2: Ok after reading again I also do agree with your point that _if_ WITH_EXTRA is used, it does seem to still put them in the wrong place. Or, "in the wrong place to solve this scenario". From my reading they do need to be in dependency order last (A needs B needs C) so perhaps this is two "bugs"...one with ensuring _STATIC variable from Cmake is used, and also ordering of the WITH_EXTRA if _it_ is used.

Sorry for all the trouble but hopefully this is a good improvement for the future :)

Ok, I tried to review it and I'm completely confused as to whether anything could be done to fix the problem. If the problem can be solved by having properly defined pkg-config for static OpenSSL or proper definition of OpenSSL-related cmake variables, then no fixes are required, right? Please correct me if I'm wrong.

It seems to be working fine now, possibly cmake or OpenSSL changed? Even
1.4.1 compiles fine now.

So I'm confused also but happy to close this :)

On Thu, Jan 21, 2021 at 6:55 AM Sektor van Skijlen notifications@github.com
wrote:

Ok, I tried to review it and I'm completely confused as to whether
anything could be done to fix the problem. If the problem can be solved by
having properly defined pkg-config for static OpenSSL or proper definition
of OpenSSL-related cmake variables, then no fixes are required, right?
Please correct me if I'm wrong.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Haivision/srt/issues/1172#issuecomment-764624109, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AAJBAYVOPYQF4USWCC6B5STS3AP3RANCNFSM4LD56GJA
.

Ok, closing then. Thanks for response.

Was this page helpful?
0 / 5 - 0 ratings