先给主目录下CMakeLists加上两句:
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
解决调试时变量看不到值
#CentOS needs to install EPEL generally otherwise many packages are not available by default.
yum -y install epel-release
#Install common deps:yum -y install git gcc gcc-c++ gdb gdb-gdbserver make cmake
#Install gflags, leveldb:yum -y install gflags-devel leveldb-devel openssl-devel thrift-devel
#If you need to enable cpu/heap profilers in examples:yum -y install gperftools-devel
#If you need to run tests, install and compile gtest-devel (which is not compiled yet):yum -y install gtest-devel
or ubuntu:
sudo apt install build-essential
sudo apt install cmake git gdb g++ make python3 gdbserver libthrift-dev libleveldb-dev libgflags-dev libgtest-dev google-perftools libgoogle-perftools-dev libboost-dev libboost-test-dev libboost-program-options-dev libboost-system-dev libboost-filesystem-dev libevent-dev libssl-dev autoconf automake libtool libxrender-dev libgl1-mesa-dev libglu1-mesa-dev libxcb-cursor0 libxcb-cursor-dev
thrift是源码编译的
https://dlcdn.apache.org/thrift/0.15.0/thrift-0.15.0.tar.gz
tar -xzvf thrift-0.15.0.tar.gz
cd thrift-0.15.0/
./bootstrap.sh
./configure --without-java
sudo make //此步骤花费时间稍长
sudo make install
thrift -version //若正常输出Thrift的版本则证明安装完成
on ubuntu modify CMakeLists.txt :
//----------------
if(WITH_THRIFT)
set(THRIFT_CPP_FLAG "-DENABLE_THRIFT_FRAMED_PROTOCOL")
find_package(THRIFT REQUIRED)
if (NOT THRIFT_FOUND)
message(FATAL_ERROR "Fail to find Thrift")
endif()
endif()
//
set(DYNAMIC_LIB
${GFLAGS_LIBRARY}
${PROTOBUF_LIBRARIES} ${protobuf_ABSL_USED_TARGETS}
${LEVELDB_LIB}
${PROTOC_LIB}
${CMAKE_THREAD_LIBS_INIT}
${THRIFT_LIBRARIES}
${ZLIB_LIBRARY}
dl
z)
/
if(WITH_THRIFT)
target_link_libraries(brpc-static ${THRIFT_LIBRARIES})
check_thrift_version(brpc-static)
endif()
Ubuntu安装Thrift0.15.0及Python环境配置-优快云博客
zlib是源码编译的
wget http://www.zlib.net/zlib-1.3.1.tar.gz
tar -xzvf zlib-1.3.1.tar.gz
cd zlib-1.3.1
./configure -prefix=/usrmake
sudo make install
/usr/include/zlib.h /usr/include/zconf.h
/usr/lib/libz.so.1.3.1
protobuf是源码编译的
sudo yum install autoconf automake libtool
or sudo apt install autoconf automake libtool
下载一个版本wget https://github.com/protocolbuffers/protobuf/releases/download/v21.9/protobuf-cpp-3.21.9.tar.gz
tar -zxvf protobuf-cpp-3.21.9.tar.gz
cd protobuf-3.21.9/
mkdir build && cd build
cmake -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DINSTALL_HEADERS=ON -DINSTALL_SHARED_LIBS=ON -DINSTALL_STATIC_LIBS=ON -DCMAKE_INSTALL_PREFIX=/usr/ ..
make -j4
sudo make install
protoc --version
/usr/include/google/protobuf
/usr/lib64/libprotobuf
or ubuntu
/usr/lib/x86_64-linux-gnu/libprotobuf.so.32
git clone https://github.com/brpc/brpc.git
一切准备就绪,到brpc的目录下执行
[root@DESKTOP-2H4O1K4 brpc]# sh config_brpc.sh --headers=/usr/include --libs=/usr/lib64
Fail to find gflags from --libs
Fail to find protobuf from --libs
Fail to find leveldb from --libs
安装位置肯定找不到,于是修改config_brpc.sh:(因为之前都安装在lib64下面)
.........................................
GFLAGS_LIB=/usr/lib64
append_linking $GFLAGS_LIB gflags
PROTOBUF_LIB=/usr/lib64
append_linking $PROTOBUF_LIB protobuf
LEVELDB_LIB=/usr/lib64
.........................................
............................................
GFLAGS_HDR=/usr/include
PROTOBUF_HDR=/usr/include
//前面protobuf也可以不用安装在local下
再执行就会成功了
make
库生成出来了
最后切换到example/echo_c++目录下,make出server和client:
(1)编译demo
cd /brpc/example/echo_c++
make -j4
(2)运行demo
./echo_server
./echo_client
解决:error while loading shared libraries:lib***.so.*: cannot open shared object file
# 编辑ld.so.conf文件
vim /etc/ld.so.conf
# 在文件末尾添上lib的完整地址,比如:
/usr/lib64
# 更新一下库文件
ldconfig
遇到编译的权限问题:Linux: Error: EACCES: permission denied Linux 解决方法
chmod -R 777 brpc
使用vscode编译遇到下面 问题
vscode build failed unable to configure the project
使用CMake::quick start命令配置CMake的编译器为gcc/g++,或者使用CMake:debug
VSCode默认不支持root用户启动,如果需要使用root用户启动,需在启动命令中加上--no-sandbox
/usr/share/code/code --no-sandbox --unity-launch
如果用vscode调试还需要把ninja安装上,参考:
ninja简介及安装_安装ninja-优快云博客
"workbench.colorCustomizations": {
"[Default Light+]": {
"editor.background": "#cce8cf",
"sideBar.background": "#cce8cf4f",
"activityBar.background": "#000000",
"panel.background": "#b8b7b76b",
"terminal.background": "#cce8cf",
},
},
"go.useLanguageServer": true,
"window.zoomLevel": 1,