1

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:

  1. What floating point exception has to do with the library?
  2. 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 direct grpc++ 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.

  • 1
    please provide a [mcve]. the exception is probably a divide by zero but could be others too, you'll need to debug it. – Alan Birtles Mar 13 '19 at 08:06
  • Generally any application that uses a C++ library will need to be linked in the same way a C++ application would get linked by a C++ compiler. – jxh Mar 13 '19 at 08:11
  • Possibly the grpc++ wrapper has FP exception handler installed. – Paul Ogilvie Mar 13 '19 at 08:14
  • Yes this is a linking issue not a compiler issue. I would be looking at whether or not the ABI is compatible or not, which spoiler alert: it's probably not. Wrappers and compilers are API level, linkers are ABI level. – BitShift Mar 13 '19 at 08:21

0 Answers0