brpc
brpc copied to clipboard
brpc编译错误
Describe the bug (描述bug) 按照文档编译brpc https://github.com/apache/incubator-brpc/blob/master/docs/cn/getting_started.md 但是发生如下错误:
yluo@ubuntu:~/incubator-brpc$ sh config_brpc.sh --headers=/usr/include --libs=/usr/lib
yluo@ubuntu:~/incubator-brpc$ make
> Linking protoc-gen-mcpack
g++ -o protoc-gen-mcpack -I./src -I/usr/include/ -L/usr/lib/x86_64-linux-gnu -std=c++0x -Xlinker "-(" src/idl_options.pb.cc src/mcpack2pb/generator.o libbrpc.a -Wl,-Bstatic -lgflags -lprotobuf -lleveldb -lsnappy -lprotoc -Wl,-Bdynamic -Xlinker "-)" -lpthread -lssl -lcrypto -ldl -lz -lrt
/usr/bin/ld: libbrpc.a(logging.o): in function `_GLOBAL__sub_I_logging.cc':
/home/yluo/incubator-brpc/src/butil/logging.cc:23: undefined reference to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'
/usr/bin/ld: libbrpc.a(logging.o): in function `__static_initialization_and_destruction_0':
/home/yluo/incubator-brpc/src/butil/logging.cc:119: undefined reference to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'
/usr/bin/ld: /home/yluo/incubator-brpc/src/butil/logging.cc:121: undefined reference to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'
/usr/bin/ld: /home/yluo/incubator-brpc/src/butil/logging.cc:124: undefined reference to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'
/usr/bin/ld: /home/yluo/incubator-brpc/src/butil/logging.cc:126: undefined reference to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'
/usr/bin/ld: libbrpc.a(logging.o):/home/yluo/incubator-brpc/src/butil/logging.cc:132: more undefined references to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)' follow
/usr/bin/ld: /tmp/ccBHCVLX.o: in function `ConvertibleIdlType_descriptor()':
idl_options.pb.cc:(.text+0x26): undefined reference to `google::protobuf::internal::AssignDescriptors(google::protobuf::internal::DescriptorTable const*, bool)'
/usr/bin/ld: /tmp/ccBHCVLX.o: in function `__static_initialization_and_destruction_0(int, int)':
idl_options.pb.cc:(.text+0xc7): undefined reference to `google::protobuf::internal::AddDescriptorsRunner::AddDescriptorsRunner(google::protobuf::internal::DescriptorTable const*)'
/usr/bin/ld: /tmp/ccBHCVLX.o:(.data.rel.ro+0x0): undefined reference to `descriptor_table_google_2fprotobuf_2fdescriptor_2eproto'
collect2: error: ld returned 1 exit status
make: *** [Makefile:241: protoc-gen-mcpack] Error 1
To Reproduce (复现方法)
yluo@ubuntu:~$ sudo apt-get install -y git g++ make libssl-dev libgflags-dev libprotobuf-dev libprotoc-dev protobuf-compiler libleveldb-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
g++ is already the newest version (4:9.3.0-1ubuntu2).
libleveldb-dev is already the newest version (1.22-3ubuntu2).
libprotobuf-dev is already the newest version (3.6.1.3-2ubuntu5).
libprotoc-dev is already the newest version (3.6.1.3-2ubuntu5).
make is already the newest version (4.2.1-1.2).
libgflags-dev is already the newest version (2.2.2-1build1).
protobuf-compiler is already the newest version (3.6.1.3-2ubuntu5).
git is already the newest version (1:2.25.1-1ubuntu3.1).
libssl-dev is already the newest version (1.1.1f-1ubuntu2.3).
0 upgraded, 0 newly installed, 0 to remove and 63 not upgraded.
yluo@ubuntu:~$ sudo apt-get install -y libsnappy-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libsnappy-dev is already the newest version (1.1.8-1build1).
0 upgraded, 0 newly installed, 0 to remove and 63 not upgraded.
yluo@ubuntu:~$ sudo apt-get install -y cmake libgtest-dev && cd /usr/src/gtest && sudo cmake . && sudo make && sudo mv libgtest* /usr/lib/ && cd -
Reading package lists... Done
Building dependency tree
Reading state information... Done
cmake is already the newest version (3.16.3-1ubuntu1).
libgtest-dev is already the newest version (1.10.0-2).
0 upgraded, 0 newly installed, 0 to remove and 63 not upgraded.
CMake Warning at CMakeLists.txt:54 (project):
VERSION keyword not followed by a value or was followed by a value that
expanded to nothing.
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/src/googletest/googletest
[ 50%] Built target gtest
[100%] Built target gtest_main
mv: cannot stat 'libgtest*': No such file or directory
yluo@ubuntu:/usr/src/gtest$ cd -
/home/yluo
yluo@ubuntu:~/incubator-brpc$ sh config_brpc.sh --headers=/usr/include --libs=/usr/lib
yluo@ubuntu:~/incubator-brpc$ make
> Linking protoc-gen-mcpack
g++ -o protoc-gen-mcpack -I./src -I/usr/include/ -L/usr/lib/x86_64-linux-gnu -std=c++0x -Xlinker "-(" src/idl_options.pb.cc src/mcpack2pb/generator.o libbrpc.a -Wl,-Bstatic -lgflags -lprotobuf -lleveldb -lsnappy -lprotoc -Wl,-Bdynamic -Xlinker "-)" -lpthread -lssl -lcrypto -ldl -lz -lrt
/usr/bin/ld: libbrpc.a(logging.o): in function `_GLOBAL__sub_I_logging.cc':
/home/yluo/incubator-brpc/src/butil/logging.cc:23: undefined reference to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'
/usr/bin/ld: libbrpc.a(logging.o): in function `__static_initialization_and_destruction_0':
/home/yluo/incubator-brpc/src/butil/logging.cc:119: undefined reference to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'
/usr/bin/ld: /home/yluo/incubator-brpc/src/butil/logging.cc:121: undefined reference to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'
/usr/bin/ld: /home/yluo/incubator-brpc/src/butil/logging.cc:124: undefined reference to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'
/usr/bin/ld: /home/yluo/incubator-brpc/src/butil/logging.cc:126: undefined reference to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'
/usr/bin/ld: libbrpc.a(logging.o):/home/yluo/incubator-brpc/src/butil/logging.cc:132: more undefined references to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)' follow
/usr/bin/ld: /tmp/ccBHCVLX.o: in function `ConvertibleIdlType_descriptor()':
idl_options.pb.cc:(.text+0x26): undefined reference to `google::protobuf::internal::AssignDescriptors(google::protobuf::internal::DescriptorTable const*, bool)'
/usr/bin/ld: /tmp/ccBHCVLX.o: in function `__static_initialization_and_destruction_0(int, int)':
idl_options.pb.cc:(.text+0xc7): undefined reference to `google::protobuf::internal::AddDescriptorsRunner::AddDescriptorsRunner(google::protobuf::internal::DescriptorTable const*)'
/usr/bin/ld: /tmp/ccBHCVLX.o:(.data.rel.ro+0x0): undefined reference to `descriptor_table_google_2fprotobuf_2fdescriptor_2eproto'
collect2: error: ld returned 1 exit status
make: *** [Makefile:241: protoc-gen-mcpack] Error 1
Expected behavior (期望行为) 编译正确
Versions (各种版本) OS: Ubuntu 20.04.2 LTS \n \l Compiler: gcc version 9.3.0 brpc: master protobuf: libprotobuf-dev is already the newest version (3.6.1.3-2ubuntu5). libprotoc-dev is already the newest version (3.6.1.3-2ubuntu5).
Additional context/screenshots (更多上下文/截图)
按照提示,编译时候,需要指定gflags gtest库
请问brpc是用了哪个版本
看到是用了master,不过这边在ubuntu20.04的docker容器中并没有复现出来,是不是本地装了其他版本的gflags库?你可以用docker环境尝试编译一下吗,排除下是本地环境的问题
老哥,问题解决了吗
I have exactly the same problem, could anyone share how to fix this, thanks a lot!
同样的问题
g++ 已经是最新版 (4:9.3.0-1ubuntu2)。 libleveldb-dev 已经是最新版 (1.22-3ubuntu2)。 libprotobuf-dev 已经是最新版 (3.6.1.3-2ubuntu5)。 libprotoc-dev 已经是最新版 (3.6.1.3-2ubuntu5)。 make 已经是最新版 (4.2.1-1.2)。 libgflags-dev 已经是最新版 (2.2.2-1build1)。 protobuf-compiler 已经是最新版 (3.6.1.3-2ubuntu5)。 git 已经是最新版 (1:2.25.1-1ubuntu3.6)。 libssl-dev 已经是最新版 (1.1.1f-1ubuntu2.16)。
同样的问题
g++ 已经是最新版 (4:9.3.0-1ubuntu2)。 libleveldb-dev 已经是最新版 (1.22-3ubuntu2)。 libprotobuf-dev 已经是最新版 (3.6.1.3-2ubuntu5)。 libprotoc-dev 已经是最新版 (3.6.1.3-2ubuntu5)。 make 已经是最新版 (4.2.1-1.2)。 libgflags-dev 已经是最新版 (2.2.2-1build1)。 protobuf-compiler 已经是最新版 (3.6.1.3-2ubuntu5)。 git 已经是最新版 (1:2.25.1-1ubuntu3.6)。 libssl-dev 已经是最新版 (1.1.1f-1ubuntu2.16)。
看是不是机器上安装了多个版本的gflags
Ubuntu 20.04 docker 试了多个提交版本没能复现。
可能是因为 gflags 的 NAMESPACE 的原因,gflags 可能有两个 NAMESPACE 一个是 google
一个是 gflags
,看下链接的 gflags 的 NAMESPACE 是否是 gflags
closed, reopen if you have further ideas. Thank you for your contributions!