OpenShot/libopenshot-audio

openshot-audio-test-sound fails to link with gold because of missing libraries

sbraz opened this issue · 6 comments

sbraz commented

cmake . -DCMAKE_EXE_LINKER_FLAGS='-Wl,-O1 -Wl,--as-needed -fuse-ld=gold' && make VERBOSE=1 results in:

[100%] Linking CXX executable openshot-audio-test-sound
cd /home/user/libopenshot-audio/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/openshot-audio-test-sound.dir/link.txt --verbose=1
/usr/bin/c++     -Wl,-O1 -Wl,--as-needed -fuse-ld=gold CMakeFiles/openshot-audio-test-sound.dir/Main.cpp.o  -o openshot-audio-test-sound -rdynamic ../libopenshot-audio.so.0.0.6 -lSM -lICE -lX11 -lXext -lasound -lfreetype -lXinerama -Wl,-rpath,/home/user/libopenshot-audio: 
../libopenshot-audio.so.0.0.6: error: undefined reference to 'pthread_mutexattr_init'
../libopenshot-audio.so.0.0.6: error: undefined reference to 'pthread_mutexattr_settype'
../libopenshot-audio.so.0.0.6: error: undefined reference to 'pthread_mutexattr_setprotocol'
../libopenshot-audio.so.0.0.6: error: undefined reference to 'pthread_mutexattr_destroy'
../libopenshot-audio.so.0.0.6: error: undefined reference to 'pthread_mutex_trylock'
../libopenshot-audio.so.0.0.6: error: undefined reference to 'dladdr'
../libopenshot-audio.so.0.0.6: error: undefined reference to 'pthread_create'
../libopenshot-audio.so.0.0.6: error: undefined reference to 'pthread_detach'
../libopenshot-audio.so.0.0.6: error: undefined reference to 'pthread_cancel'
../libopenshot-audio.so.0.0.6: error: undefined reference to 'pthread_setname_np'
../libopenshot-audio.so.0.0.6: error: undefined reference to 'pthread_setaffinity_np'
../libopenshot-audio.so.0.0.6: error: undefined reference to 'dlopen'
../libopenshot-audio.so.0.0.6: error: undefined reference to 'dlclose'
../libopenshot-audio.so.0.0.6: error: undefined reference to 'dlsym'
collect2: error: ld returned 1 exit status
src/CMakeFiles/openshot-audio-test-sound.dir/build.make:99: recipe for target 'src/openshot-audio-test-sound' failed

Adding dl pthread to target_link_libraries in src/CMakeLists.txt fixes the problem.

sbraz commented

@jonoomph could you look at this issue too while you're around? :)

Investigating now...

I'm concerned about the compatibility of this on Windows and Mac. I think we'll need to use the ${CMAKE_DL_LIBS} variable, and possibly a similar type variable for pthreads, to make things nice and safe and compatible. Feel free to experiment with that, and see if that works.

I confirm the current underlinkage problem as reported by the Debian toolchain:

dpkg-shlibdeps: warning: symbol pthread_setaffinity_np used by debian/libopenshot-audio3/usr/lib/x86_64-linux-gnu/libopenshot-audio.so.0.1.2 found in none of the libraries
dpkg-shlibdeps: warning: symbol pthread_mutexattr_destroy used by debian/libopenshot-audio3/usr/lib/x86_64-linux-gnu/libopenshot-audio.so.0.1.2 found in none of the libraries
dpkg-shlibdeps: warning: symbol dlsym used by debian/libopenshot-audio3/usr/lib/x86_64-linux-gnu/libopenshot-audio.so.0.1.2 found in none of the libraries
dpkg-shlibdeps: warning: symbol pthread_mutex_trylock used by debian/libopenshot-audio3/usr/lib/x86_64-linux-gnu/libopenshot-audio.so.0.1.2 found in none of the libraries
dpkg-shlibdeps: warning: symbol pthread_setname_np used by debian/libopenshot-audio3/usr/lib/x86_64-linux-gnu/libopenshot-audio.so.0.1.2 found in none of the libraries
dpkg-shlibdeps: warning: symbol pthread_mutexattr_settype used by debian/libopenshot-audio3/usr/lib/x86_64-linux-gnu/libopenshot-audio.so.0.1.2 found in none of the libraries
dpkg-shlibdeps: warning: symbol dladdr used by debian/libopenshot-audio3/usr/lib/x86_64-linux-gnu/libopenshot-audio.so.0.1.2 found in none of the libraries
dpkg-shlibdeps: warning: symbol dlopen used by debian/libopenshot-audio3/usr/lib/x86_64-linux-gnu/libopenshot-audio.so.0.1.2 found in none of the libraries
dpkg-shlibdeps: warning: symbol pthread_mutexattr_setprotocol used by debian/libopenshot-audio3/usr/lib/x86_64-linux-gnu/libopenshot-audio.so.0.1.2 found in none of the libraries
dpkg-shlibdeps: warning: symbol dlclose used by debian/libopenshot-audio3/usr/lib/x86_64-linux-gnu/libopenshot-audio.so.0.1.2 found in none of the libraries
dpkg-shlibdeps: warning: 4 other similar warnings have been skipped (use -v to see them all)

Right now, this can be fixed by manually appending -pthread to CFLAGS and -lpthread -ldl to LDFLAGS but it would be best if CMake could take care of that.

I'm concerned about the compatibility of this on Windows and Mac. I think we'll need to use the ${CMAKE_DL_LIBS} variable, and possibly a similar type variable for pthreads, to make things nice and safe and compatible. Feel free to experiment with that, and see if that works.

I agree. For pthread, there's Threads package you can find and configure appropriately. @sbraz, could you update the patch, please?

This seems to have reappeared, trying to compile libopenshot-audio-0.2.2 on Gentoo Linux using the gold linker:

libopenshot-audio.so.0.2.2: error: undefined reference to 'pthread_mutexattr_init'
libopenshot-audio.so.0.2.2: error: undefined reference to 'pthread_mutexattr_settype'
libopenshot-audio.so.0.2.2: error: undefined reference to 'pthread_mutexattr_setprotocol'
libopenshot-audio.so.0.2.2: error: undefined reference to 'pthread_mutexattr_destroy'
libopenshot-audio.so.0.2.2: error: undefined reference to 'pthread_mutex_trylock'
libopenshot-audio.so.0.2.2: error: undefined reference to 'pthread_create'
libopenshot-audio.so.0.2.2: error: undefined reference to 'pthread_attr_setstacksize'
libopenshot-audio.so.0.2.2: error: undefined reference to 'pthread_detach'
libopenshot-audio.so.0.2.2: error: undefined reference to 'pthread_cancel'
libopenshot-audio.so.0.2.2: error: undefined reference to 'pthread_setname_np'
libopenshot-audio.so.0.2.2: error: undefined reference to 'pthread_setaffinity_np'
libopenshot-audio.so.0.2.2: error: undefined reference to 'pthread_condattr_setclock'
libopenshot-audio.so.0.2.2: error: undefined reference to 'pthread_join'
libopenshot-audio.so.0.2.2: error: undefined reference to 'pthread_cond_clockwait'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

After changing from gold to bfd, it compiles fine.