title: C++ Shared library gives floating point exception when linked with C application
body: <p><strong>Background:</strong></p>
  
  <p>A C++ library for <code>etcd client</code> having APIs to communicate with <code>etcd server</code>, to use this library in C application, we wrote C++ wrappers over this library so that it can be called by C application.</p>
  
  <p>Created a shared library using the below command:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>placed this library to default library path <code>/usr/local/lib</code> and load the library with <code>sudo ldconfig</code>.</p>
  
  <p>Now using this <code>etcd_c++</code> library APIs, wrote a C code to insert simple key-value to <code>etcd keyspace</code>. Compiled using below command:</p>
  
  <pre><code>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++
  </code></pre>
  
  <p>The compilation goes fine. But while executing the resulted binary, it gives floating point exception in <code>grpc++</code> library.</p>
  
  <p>Questions:</p>
  
  <ol>
  <li>What <code>floating point exception</code> has to do with the library?</li>
  <li>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 <code>floating point exception</code>.Now If we replace the wrapper API with direct <code>grpc++</code> library API, in the C++ code, it works fine. Is it a linking issue?</li>
  </ol>
  
  <p>Compiling a C++ application:</p>
  
  <pre><code>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++
  </code></pre>
  
  <p><strong>EDIT</strong>: Some findings, <a href="https://bugs.launchpad.net/ubuntu/+source/grpc/+bug/1797000" rel="nofollow noreferrer">https://bugs.launchpad.net/ubuntu/+source/grpc/+bug/1797000</a></p>
  
  <p>Though We are not using <code>-Wl,-Bsymbolic-functions</code> option, but the issue is somewhat similar to above.  </p>