[C ++共享库与C应用程序链接时给出浮点异常

问题描述 投票:0回答:1

背景:

etcd client的C ++库,具有与etcd server进行通信的API,以便在C应用程序中使用此库,我们在该库上编写了C ++包装程序,以便C应用程序可以调用它。

使用以下命令创建共享库:

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

将该库放置到默认库路径/usr/local/lib,并用sudo ldconfig加载库。

[现在使用此etcd_c++库API,编写了C代码,将简单的键值插入etcd keyspace。使用以下命令进行编译:

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++

编译正常。但是在执行结果二进制文件时,它在grpc++库中提供了浮点异常。

问题:

  1. floating point exception与库有什么关系?
  2. 我们认为这可能是C到C ++过渡的问题,但是当使用相同的包装API将相同的C代码转换为C ++时。给出floating point exception。现在,如果用直接grpc++库API替换包装API,则在C ++代码中,它可以正常工作。这是链接问题吗?

编译C ++应用程序:

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:一些发现,https://bugs.launchpad.net/ubuntu/+source/grpc/+bug/1797000

虽然我们没有使用-Wl,-Bsymbolic-functions选项,但问题与上面的问题有些相似。

c++ c shared-libraries grpc etcd3
1个回答
0
投票

此grpc ++的任何解决方案。...什么是解决方案,如果我必须将其链接为.c文件。无法从.c文件切换到.cc?请帮忙???

© www.soinside.com 2019 - 2024. All rights reserved.