I have C++ app that uses Boost.Asio and OpenSSL. I try to build app in Ubuntu 16.04 and I am stucked.
All .cpp
files compiled correctly. Compilation flags: -m64 -O0 -Wall -Wextra -MMD -std=c++11
With linking I have a problem. My command line for the linker:
LIBS = -static -L$(BOOST_LIBS) -l:..boostlibs \
-L$(OPENSSL_LIBS) -l:libssl.a -l:libcrypto.a \
-Wl,-Bdynamic -lc -ldl -lpthread \
-Wl,-dynamic-linker=/lib64/ld-linux-x86-64.so.2
g++ *.o $(LIBS) -o executablefile
(*.o
means list of all object files needed for the app)
This command works fine, app can be launched. But in this app blocks try{} catch(...){}
do not work at all. If any exception is thrown - my app terminated.
I made simple app and used only shared libs to build it. I.e. I removed -Wl,-Bdynamic
from the linker options. All works fine, exceptions catched.
But my app requires shared libs and I do not know what to do with that.
How to fix catching of exceptions?
P.S.
Arguments -Wl,-Bdynamic -lc -ldl -lpthread
needed because without them I get error from the linker:
/home/.../openssl/openssl-1.0.2h-x64-build/lib/libcrypto.a(dso_dlfcn.o): In function
dlfcn_globallookup': dso_dlfcn.c:(.text+0x11): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /home/.../xxx.o: In function
boost::asio::detail::resolver_service::resolve(std::shared_ptr&, boost::asio::ip::basic_resolver_query const&, boost::system::error_code&)': xxx.cpp:(.text._ZN5boost4asio6detail16resolver_serviceINS0_2ip3tcpEE7resolveERSt10shared_ptrIvERKNS3_20basic_resolver_queryIS4_EERNS_6system10error_codeE[_ZN5boost4asio6detail16resolver_serviceINS0_2ip3tcpEE7resolveERSt10shared_ptrIvERKNS3_20basic_resolver_queryIS4_EERNS_6system10error_codeE]+0xd7): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
This error perfectly described here and seems that I have to use shared libraries.
Argument -Wl,-dynamic-linker=/lib64/ld-linux-x86-64.so.2
needed because g++
not able to locate path to the shared lib ld
. And if I try to launch compiled app I got error: No such file or directory
.
P.S. 2
I use Ubuntu 16.04.2 and gcc 5.4.0
UPD
Just to be clear.
If I add code below to the start of the main
function - my app terminated.
try
{
throw std::exception();
}
catch(...)
{
std::cerr << "hello from the catch.";
}