sogou / srpc

RPC framework based on C++ Workflow. Supports SRPC, Baidu bRPC, Tencent tRPC, thrift protocols.
Apache License 2.0
1.95k stars 385 forks source link

srpc 编译错误 #252

Closed CarlLyt closed 2 years ago

CarlLyt commented 2 years ago

gcc/g++ 版本是 11.2.1 20220127 (Red Hat 11.2.1-9) (GCC) protoc 的版本是 libprotoc 3.11.4

编译 srpc 的源码报错: [ 61%] Building CXX object src/compress/CMakeFiles/compress.dir/rpc_compress_snappy.cc.o In file included from /usr/local/include/google/protobuf/message.h:120, from /home/srpc/src/rpc_basic.h:22, from /home/srpc/src/compress/rpc_compress_snappy.h:20, from /home/srpc/src/compress/rpc_compress_snappy.cc:19: /usr/local/include/google/protobuf/arena.h: In member function ‘void* google::protobuf::Arena::AllocateInternal(bool)’: /usr/local/include/google/protobuf/arena.h:536:15: error: cannot use ‘typeid’ with ‘-fno-rtti’ 536 | AllocHook(RTTI_TYPE_ID(T), n); | ^~~~~~~~~~~~ /usr/local/include/google/protobuf/arena.h: In member function ‘T* google::protobuf::Arena::CreateInternalRawArray(size_t)’: /usr/local/include/google/protobuf/arena.h:599:15: error: cannot use ‘typeid’ with ‘-fno-rtti’ 599 | AllocHook(RTTI_TYPE_ID(T), n); |

加了CXXFLAGS -fno-rtti 报错信息如下: /home/srpc/workflow/src/manager/UpstreamManager.cc: In static member function ‘static int UpstreamManager::upstream_add_server(const string&, const string&, const AddressParams*)’: /home/srpc/workflow/src/manager/UpstreamManager.cc:169:34: error: ‘dynamic_cast’ not permitted with ‘-fno-rtti’ 169 | UPSGroupPolicy *policy = dynamic_cast<UPSGroupPolicy *>(ns->get_policy(name.c_str())); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/srpc/workflow/src/manager/UpstreamManager.cc: In static member function ‘static int UpstreamManager::upstream_remove_server(const string&, const string&)’: /home/srpc/workflow/src/manager/UpstreamManager.cc:185:34: error: ‘dynamic_cast’ not permitted with ‘-fno-rtti’ 185 | UPSGroupPolicy *policy = dynamic_cast<UPSGroupPolicy *>(ns->get_policy(name.c_str())); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/srpc/workflow/src/manager/UpstreamManager.cc: In static member function ‘static int UpstreamManager::upstream_delete(const string&)’: /home/srpc/workflow/src/manager/UpstreamManager.cc:197:34: error: ‘dynamic_cast’ not permitted with ‘-fno-rtti’ 197 | UPSGroupPolicy *policy = dynamic_cast<UPSGroupPolicy *>(ns->del_policy(name.c_str())); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/srpc/workflow/src/manager/UpstreamManager.cc: In static member function ‘static std::vector<std::basic_string<char> > UpstreamManager::upstream_main_address_list(const string&)’: /home/srpc/workflow/src/manager/UpstreamManager.cc:211:34: error: ‘dynamic_cast’ not permitted with ‘-fno-rtti’ 211 | UPSGroupPolicy *policy = dynamic_cast<UPSGroupPolicy *>(ns->get_policy(name.c_str())); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/srpc/workflow/src/manager/UpstreamManager.cc: In static member function ‘static int UpstreamManager::upstream_disable_server(const string&, const string&)’: /home/srpc/workflow/src/manager/UpstreamManager.cc:223:34: error: ‘dynamic_cast’ not permitted with ‘-fno-rtti’ 223 | UPSGroupPolicy *policy = dynamic_cast<UPSGroupPolicy *>(ns->get_policy(name.c_str())); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/srpc/workflow/src/manager/UpstreamManager.cc: In static member function ‘static int UpstreamManager::upstream_enable_server(const string&, const string&)’: /home/srpc/workflow/src/manager/UpstreamManager.cc:239:34: error: ‘dynamic_cast’ not permitted with ‘-fno-rtti’ 239 | UPSGroupPolicy *policy = dynamic_cast<UPSGroupPolicy *>(ns->get_policy(name.c_str())); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/srpc/workflow/src/manager/UpstreamManager.cc: In static member function ‘static int UpstreamManager::upstream_replace_server(const string&, const string&, const AddressParams*)’: /home/srpc/workflow/src/manager/UpstreamManager.cc:256:34: error: ‘dynamic_cast’ not permitted with ‘-fno-rtti’ 256 | UPSGroupPolicy *policy = dynamic_cast<UPSGroupPolicy *>(ns->get_policy(name.c_str())); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

holmes1412 commented 2 years ago

你好~srpc除了会用到protoc进行代码生成以外,编译lib期间需要依赖libprotobuf.so。

可以看看你本地的protobuf库是什么版本吗?

进一步讲述一下这个问题:snappy-1.1.9的某两个类是-no-rtti,我们派生了它们因此srpc里的rpc_compress_snappy.cc文件也是no-rtti,其他文件是没有的。但是先前有遇到过和最新版protobuf一起编译的时候,出现类似“/usr/local/include/google/protobuf/arena.h:599:15: error: cannot use ‘typeid’ with ‘-fno-rtti’ 599 | AllocHook(RTTI_TYPE_ID(T), n); |”的错误。因此才比较怀疑你的libprotobuf版本比较高。

麻烦确认下、换个适中的版本(比如3.11.4就挺好),然后再试试~

CarlLyt commented 2 years ago

libprotobuf 的版本是:/usr/local/lib/libprotobuf.so.22 protobuf的可执行文件和链接库都是从git仓库源码编译的,在编译之前已经讲原有的 protobuf2 和 protofbuf3都删除了。