Background:
A C++ library for etcd client
having APIs to communicate with etcd server
, to use this library in C application, we wrote C++ wrappers over this library so that it can be called by C application.
Created a shared library using the below command:
g++-7 -ggdb -fPIC -shared -o libetcd_c++.so etcd_client_wrapper.cc etcd_client_txn_wrapper.cc etcd_client.cc etcd_client_txn.cc utils/string.cc pb/*.cc -std=c++1z -I ./pb/etcd -rdynamic -Wl,-call_shared -lglog -lprotobuf -lgrpc++ -lgrpc -Wl,-call_shared -lpthread -ldl -lc
placed this library to default library path /usr/local/lib
and load the library with sudo ldconfig
.
Now using this etcd_c++
library APIs, wrote a C code to insert simple key-value to etcd keyspace
. Compiled using below command:
gcc -ggdb -o cwrap sample_wrapper.c -rdynamic -pthread -static-libstdc++ -Wl,-non_shared -lglog -lprotobuf -pthread -lz -lgrpc++ -lprotobuf -lgrpc -lz -lcares -lssl -lcrypto -lunwind -llzma -lgflags -Wl,-call_shared -lpthread -ldl -letcd_c++ -lstdc++
The compilation goes fine. But while executing the resulted binary, it gives floating point exception in grpc++
library.
Questions:
- What
floating point exception
has to do with the library? - We thought it might be an issue with C to C++ transition, but when converted the same C code to C++ with same wrapper API. Gives the
floating point exception
.Now If we replace the wrapper API with directgrpc++
library API, in the C++ code, it works fine. Is it a linking issue?
Compiling a C++ application:
g++-7 -ggdb -o wrap example.cc -std=c++1z -rdynamic -pthread -static-libstdc++ -Wl,-non_shared -lglog -lprotobuf -pthread -lz -lgrpc++ -lprotobuf -lgrpc -lz -lcares -lssl -lcrypto -lunwind -llzma -lgflags -Wl,-call_shared -lpthread -ldl -letcd_c++
EDIT: Some findings, https://bugs.launchpad.net/ubuntu/+source/grpc/+bug/1797000
Though We are not using -Wl,-Bsymbolic-functions
option, but the issue is somewhat similar to above.