discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Crash occurs when catching std::exception in Objective-C++ code comp


From: Lobron, David
Subject: Re: Crash occurs when catching std::exception in Objective-C++ code compiled with clang on Linux and using libobjc2
Date: Fri, 17 Nov 2017 15:39:58 +0000

Thank you for the help!

> It seems to be missing the linker command line for building the CXXException 
> test.  It’s probably worth taking a step back at this point:
> 
> On Linux platforms, it’s common to provide libsupc++ (the GNU C++ runtime 
> library) statically linked into libstdc++ (the GNU C++ standard library).  
> This is somewhat awkward, because this means that the only way to use symbols 
> in libsupc++ is to add a dependency on libstdc++.  I’ve tried to avoid that 
> for libobjc, because libstdc++ is a big library and is completely unused for 
> pure Objective-C programs.
> 
> On FreeBSD, we ship libcxxrt (the BSD C++ runtime, which I wrote) as a 
> separate .so and link both libstdc++ and libc++ (the LLVM C++ standard 
> library) to it dynamically, so we can support programs linked to both.  This 
> means that on FreeBSD we ship libobjc.so dynamically linked to libcxxrt.so, 
> and that doesn’t add much to the dependency footprint for any Objective-C 
> project.
> 
> By default, the libobjc CMake build looks for libcxxrt.so or libsupc++.so 
> and, if it doesn’t find them, will build a libobjcxx.so that links to 
> libstdc++ and to libobjc.so.  This extra library provides the required 
> functionality for Objective-C++.  If you are seeing this being built, then 
> you will need to link it for Objective-C++ to work.  This configuration isn’t 
> as well tested, because I don’t use any platforms that package things like 
> this on a regular basis.
> 
> TL;DR: Can you try adding -lobjcxx and see if that makes things work again 
> for you?

I tried adding this to Test/CMakeFiles/CXXExceptions.dir/link.txt and 
Test/CMakeFiles/CXXExceptions_optimised.dir/link.txt, but the linker couldn't 
find the shared library:

/usr/bin/ld.bfd.real: cannot find -lobjcxx

I located the .so at the root of my build tree:

(ALSI8)dlobron@bos-lps80:~/build/clangport/akamai/libobjc2$ find . -name 
libobjcxx.so
./libobjc2-1.8.1/build/libobjcxx.so

I added -L.. to the linker command.  The linker was then able to find 
libobjcxx.so, but unfortunately the exception errors came back, along with some 
new ones from libobjcxx.so:

(ALSI8)dlobron@bos-lps80:~/build/clangport/akamai/libobjc2/libobjc2-1.8.1/build/Test$
 /home/dlobron/build/clangport/akamai/llvm/llvm-5.0.0.install/bin/clang 
-std=gnu99  -fexceptions  -rdynamic -lobjcxx  
CMakeFiles/CXXExceptions_optimised.dir/CXXException.m.o 
CMakeFiles/CXXExceptions_optimised.dir/CXXException.cc.o  -o 
CXXExceptions_optimised 
-Wl,-rpath,/home/dlobron/build/clangport/akamai/libobjc2/libobjc2-1.8.1/build 
../libobjc.so.4.6 -L..             
CMakeFiles/CXXExceptions_optimised.dir/CXXException.cc.o: In function 
`throw_int':
/home/dlobron/build/clangport/akamai/libobjc2/libobjc2-1.8.1/Test/CXXException.cc:(.text+0x7):
 undefined reference to `__cxa_allocate_exception'
/home/dlobron/build/clangport/akamai/libobjc2/libobjc2-1.8.1/Test/CXXException.cc:(.text+0x12):
 undefined reference to `typeinfo for int'
/home/dlobron/build/clangport/akamai/libobjc2/libobjc2-1.8.1/Test/CXXException.cc:(.text+0x1c):
 undefined reference to `__cxa_throw'
CMakeFiles/CXXExceptions_optimised.dir/CXXException.cc.o: In function 
`catchall':
/home/dlobron/build/clangport/akamai/libobjc2/libobjc2-1.8.1/Test/CXXException.cc:(.text+0x2c):
 undefined reference to `__cxa_begin_catch'
/home/dlobron/build/clangport/akamai/libobjc2/libobjc2-1.8.1/Test/CXXException.cc:(.text+0x3b):
 undefined reference to `__cxa_rethrow'
/home/dlobron/build/clangport/akamai/libobjc2/libobjc2-1.8.1/Test/CXXException.cc:(.text+0x43):
 undefined reference to `__cxa_end_catch'
CMakeFiles/CXXExceptions_optimised.dir/CXXException.cc.o: In function 
`__clang_call_terminate':
/home/dlobron/build/clangport/akamai/libobjc2/libobjc2-1.8.1/Test/CXXException.cc:(.text.__clang_call_terminate[__clang_call_terminate]+0x2):
 undefined reference to `__cxa_begin_catch'
/home/dlobron/build/clangport/akamai/libobjc2/libobjc2-1.8.1/Test/CXXException.cc:(.text.__clang_call_terminate[__clang_call_terminate]+0x7):
 undefined reference to `std::terminate()'
CMakeFiles/CXXExceptions_optimised.dir/CXXException.cc.o:(.eh_frame+0x3f): 
undefined reference to `__gxx_personality_v0'
../libobjcxx.so: undefined reference to `operator delete(void*)'
../libobjcxx.so: undefined reference to `std::type_info::__is_pointer_p() const'
../libobjcxx.so: undefined reference to `typeinfo for std::type_info'
../libobjcxx.so: undefined reference to `std::type_info::__is_function_p() 
const'
../libobjcxx.so: undefined reference to `__dynamic_cast'
../libobjcxx.so: undefined reference to 
`std::type_info::__do_upcast(__cxxabiv1::__class_type_info const*, void**) 
const'
../libobjcxx.so: undefined reference to `vtable for std::type_info'
../libobjcxx.so: undefined reference to `vtable for 
__cxxabiv1::__si_class_type_info'
../libobjcxx.so: undefined reference to `std::type_info::~type_info()'
clang-6.0: error: linker command failed with exit code 1 (use -v to see 
invocation)

Drat! :)

Do you know where I might go from here?  BTW, in case I did not note them 
before, here is a list of the versions I am using- please let me know if I 
should try upgrading one of these:

libobjc2-1.8.1
gnustep-base-1.24.9
gnustep-make-2.6.0
llvm-5.0.0
Ubuntu Linux with kernel 3.13.0-125-generic

Thanks!

--David






reply via email to

[Prev in Thread] Current Thread [Next in Thread]