libobjc2 icon indicating copy to clipboard operation
libobjc2 copied to clipboard

Build fails on slackware-current (rc2 give or take a couple weeks) with: undefined reference to `std::__throw_length_error(char const*)

Open cball01 opened this issue 2 years ago • 2 comments

This is with source pulled from git, version 2.1 doesn't build with a different set of undefined references to std:: things. 1.8.1 doesn't build because of an issue that has since been addressed.

bang:/home/cball/local/src/libobjc2/build# uname -a
Linux bang.powertrader.com 5.15.0 #1 SMP PREEMPT Wed Nov 3 14:07:21 CDT 2021 x86_64 Intel(R) Xeon(R) E-2136 CPU @ 3.30GHz GenuineIntel GNU/Linux
bang:/home/cball/local/src/libobjc2/build# export CC=clang; export CXX=clang++;cmake ..;make
-- The C compiler identification is Clang 13.0.0
-- The ASM compiler identification is Clang
-- Found assembler: /usr/bin/clang
-- The CXX compiler identification is Clang 13.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Testing C++ interop
-- Testing /usr/lib64/libsupc++.a as the C++ runtime library
-- Using /usr/lib64/libsupc++.a as the C++ runtime library
-- 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  
-- GNUstep install type set to LOCAL
-- Performing Test CXA_ALLOCATE_EXCEPTION_NOEXCEPT_COMPILES
-- Performing Test CXA_ALLOCATE_EXCEPTION_NOEXCEPT_COMPILES - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/cball/local/src/libobjc2/build
[  0%] Generating eh_trampoline.s
Scanning dependencies of target objc
.
.
.
[  9%] Building CXX object Test/CMakeFiles/ObjCXXEHInterop_arc_legacy_optimised.dir/ObjCXXEHInterop_arc.mm.o
[  9%] Building C object Test/CMakeFiles/ObjCXXEHInterop_arc_legacy_optimised.dir/ObjCXXEHInterop_arc.m.o
[  9%] Linking C executable ObjCXXEHInterop_arc_legacy_optimised
/usr/bin/ld: ../libobjc.so.4.6: undefined reference to `std::__throw_length_error(char const*)'
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Test/CMakeFiles/ObjCXXEHInterop_arc_legacy_optimised.dir/build.make:118: Test/ObjCXXEHInterop_arc_legacy_optimised] Error 1
make[1]: *** [CMakeFiles/Makefile2:536: Test/CMakeFiles/ObjCXXEHInterop_arc_legacy_optimised.dir/all] Error 2
bang:/home/cball/local/src/libobjc2/build# ldd libobjc.so.4.6 
        linux-vdso.so.1 (0x00007ffdd8b30000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f04a248d000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f04a246c000)
        libgcc_s.so.1 => /usr/lib64/libgcc_s.so.1 (0x00007f04a2451000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f04a2271000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f04a2663000)

Thoughts, mockery?

cball01 avatar Dec 02 '21 02:12 cball01

This looks as if you're seeing this is because we're finding libsupc++.a when we should be looking for only a shared library. Normally on libstdc++ platforms, we use libstdc++.so as the C++ runtime library, which gives us this symbol.

davidchisnall avatar Dec 04 '21 19:12 davidchisnall

Thank you, disabling the libsupc++ test did the trick for me.

If the static version of the library is never what people want, the magic is that on CMakeLists.txt line 228: find_library(CXX_RUNTIME_LIB NAMES ${CXX_RUNTIME_NAME_FULL} ${CXX_RUNTIME_NAME})

Should probably be more like: find_library(CXX_RUNTIME_LIB NAMES ${CXX_RUNTIME_NAME_FULL} )

cball01 avatar Dec 10 '21 01:12 cball01

The CMake has now been reworked and doesn't try to link directly against a C++ runtime. Can you try again?

davidchisnall avatar Feb 19 '23 16:02 davidchisnall

Looks good, builds clean now give or take some slight whinging from clang:

In file included from /home/cball/local/src/libobjc2-test/libobjc2/dtable.h:3:
/home/cball/local/src/libobjc2-test/libobjc2/sarray2.h:55:8: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
        void *data[data_size];
              ^
1 warning generated.

cball01 avatar Feb 21 '23 18:02 cball01