背景:
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++
库中提供了浮点异常。
问题:
floating point exception
与库有什么关系?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
选项,但问题与上面的问题有些相似。
此grpc ++的任何解决方案。...什么是解决方案,如果我必须将其链接为.c文件。无法从.c文件切换到.cc?请帮忙???