如何使brpc静态链接protobuf
- Dominant language
- C++
- Stars
- 17.6k
- Forks
- 4.1k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 69
Description
编译环境:
- gcc:8.5
- cmake:3.20.2
- Linux kernel:4.18.0-425.3.1.el8.x86_64(rocky 8.6)
我想使用cmake静态链接brpc所有依赖,gflags已经成功了,但是protobuf很难搞。
我自己编译安装了protobuf v4.23.0版本
[https://github.com/protocolbuffers/protobuf/blob/v4.23.0/cmake/README.md
](https://github.com/protocolbuffers/protobuf/blob/v4.23.0/cmake/README.md
)
不知道是不是protobuf官方readme写的太过简略, sudo make install 并没有FindProtobuf.cmake,请问如何解决下面brpc的报错?
```
CMake Error at tools/rpc_view/CMakeLists.txt:18 (include):
include could not find requested file:
FindProtobuf
CMake Error at tools/rpc_view/CMakeLists.txt:19 (protobuf_generate_cpp):
Unknown CMake command "protobuf_generate_cpp".
-- Configuring incomplete, errors occurred!
````
在我关掉构建BUILD_BRPC_TOOLS后,由于protobuf要求c++14标准上,但是brpc默认是c++11,报如下错误:
```
In file included from /usr/local/include/absl/base/config.h:86,
from /usr/local/include/absl/base/attributes.h:37,
from /usr/local/include/absl/strings/string_view.h:39,
from /usr/local/include/google/protobuf/stubs/common.h:44,
from /usr/local/include/google/protobuf/io/zero_copy_stream.h:110,
from /brpc-1.6.0/src/butil/zero_copy_stream_as_streambuf.h:24,
from /brpc-1.6.0/src/butil/zero_copy_stream_as_streambuf.cpp:21:
/usr/local/include/absl/base/policy_checks.h:79:2: error: #error "C++ versions less than C++14 are not supported."
#error "C++ versions less than C++14 are not supported."
```
brpc改为c++14报如下错误:
```
[ 0%] Generating idl_options.pb.h, idl_options.pb.cc
make[2]: I: Command not found
Error copying file "brpc-1.6.0/build/idl_options.pb.h" to "brpc-1.6.0/build/output/include/idl_options.pb.h".
make[2]: *** [CMakeFiles/PROTO_LIB.dir/build.make:75: idl_options.pb.h] Error 1
make[1]: *** [CMakeFiles/Makefile2:105: CMakeFiles/PROTO_LIB.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
```
在CMAKE_PREFIX_PATH 后面追加自己编译的protobuf路径,前面的问题都解决了。
```
list(APPEND CMAKE_PREFIX_PATH "xxx/protobuf_install/")
find_package(Protobuf REQUIRED)
```
但是cmake报下面错误:
```
CMake Warning at /protobuf_install/lib64/cmake/protobuf/protobuf-config.cmake:9 (find_package):
Found package configuration file:
/protobuf_install/lib64/cmake/absl/abslConfig.cmake
but it set absl_FOUND to FALSE so package "absl" is considered to be NOT
FOUND. Reason given by package:
The following imported targets are referenced, but are missing:
protobuf::gmock
Call Stack (most recent call first):
CMakeLists.txt:154 (find_package)
```
查了一下,关掉protobuf的test重新编译即可。
`cmake .. -DCMAKE_CXX_STANDARD=14 -D CMAKE_INSTALL_PREFIX=/protobuf_install/ -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release`
Contributor guide
Research direction
Start with tools/rpc_view/CMakeLists.txt and the top-level CMakeLists.txt, then reproduce the configuration using the reported protobuf 4.23.0 installation and CMAKE_PREFIX_PATH. Check the generated protobuf targets and the C++14 build path, including the protobuf_BUILD_TESTS=OFF configuration. Done means a clean configure and build with static protobuf dependencies and no missing FindProtobuf, imported target, or generated-file errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100