VOID001 opened a new issue #1498:
URL: https://github.com/apache/incubator-brpc/issues/1498
**Describe the bug (描述bug)**
The example programs including `echo_server` and `echo_client` cannot run
and complains about a linking problem:
```
ERROR: something wrong with flag 'flagfile' in file
'/build/gflags/src/gflags-2.2.2/src/gflags.cc'. One possibility: file
'/build/gflags/src/gflags-2.2.2/src/gflags.cc' is being linked both statically
and dynamically into this executable.
```
**To Reproduce (复现方法)**
1. `./config_brpc.sh --headers=/usr/include --libs=/usr/lib --with-glog;
make -j8`
2. `make -C example/echo_c++/; example/echo_c++/echo_server`
**Expected behavior (期望行为)**
Server should start
**Versions (各种版本)**
OS: Arch Linux Linux 5.12.15-arch1-1 #1 SMP PREEMPT Wed, 07 Jul 2021
23:35:29 +0000 x86_64 GNU/Linux
Compiler: g++ (GCC) 11.1.0
brpc: d37a553fa8f5bd0a491a854048c9302ee42c00f4
protobuf:
**Additional context/screenshots (更多上下文/截图)**
I think the problem is caused by "both static libgflags.a and dynamic
libgflags.so" is linked in the example program. Following is my config.mk
(generated from config_brpc.sh)
```
# Generated by config_brpc.sh, don't modify manually
SYSTEM=Linux
HDRS=/usr/include/
LIBS=/usr/lib
PROTOC=/usr/bin/protoc
PROTOBUF_HDR=/usr/include/
CC=gcc
CXX=g++
GCC_VERSION=110100
STATIC_LINKINGS= -lgflags
DYNAMIC_LINKINGS=-lpthread -lrt -lssl -lcrypto -ldl -lz -lprotobuf -lleveldb
CPPFLAGS=-DBRPC_WITH_GLOG=1 -DGFLAGS_NS=google -g
ifeq ($(NEED_LIBPROTOC), 1)
DYNAMIC_LINKINGS+=-lprotoc
endif
ifeq ($(NEED_GPERFTOOLS), 1)
DYNAMIC_LINKINGS+=-ltcmalloc_and_profiler
endif
DYNAMIC_LINKINGS+=-lglog
ifeq ($(NEED_GTEST), 1)
DYNAMIC_LINKINGS+=-lgtest
DYNAMIC_LINKINGS+=-lgtest_main
endif
```
In the config.mk file, libgflags is detected as a static library to link,
however the when building example is trying to link `libbrpc.so` as well as
`libgflags.a`, results in a incorrect linking setting.
There are two solutions to workaround
1. Pass `LINK_SO=0` environment variable when building examples
2. dynamic link DYNAMIC_LINKINGS and STATIC_LINKINGS (such as gflags in this
case) when building examples.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]