C++高性能服务器框架 – SYLAR – 01环境配置
视频教程
[C++高级教程]Linux C++ 开发环境搭建(sylar)
环境安装包
sylar-env-1.0.1-1.el7.x86_64.rpm (在QQ群:8151915 群文件中)
Centos7.6环境直接安装,安装路径独立于系统路径,方便删除不影响系统软件
sudo rpm -ivh sylar-env-1.0.1-1.el7.x86_64.rpm
yum install glibc-static
yum install glibc-devel
yum install boost-devel
yum install mysql-devel
yum install git
git clone https://github.com/sylar-yin/sylar.git
cd sylar
make
make -j4
环境配置
- VisualBox安装
- Linux系统
- ohmyzsh
- VIM7.4+
- GCC 4.8+
- GDB 8.3
- CMAKE 2.8+
- ragel
- boost
- 其他
VisualBox安装
http://download.virtualbox.org/virtualbox/6.0.8/VirtualBox-6.0.8-130520-OSX.dmg
Linux系统安装
从centos官网下载ios文件,虚拟机加载ios文件,进行最小化安装即可
视频中采用的是centos7.6,链接地址 http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1810.iso
修改 /etc/sysconfig/network-scripts/ifcfg-enp0s3
ONBOOT=YES
修改VisualBox网络模式为 桥接网卡
然后执行网卡重启 service network restart
(具体名称和网卡一致)
ohmyzsh
- yum install zsh
- yum install git
- sh -c “$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)”
VIM 安装
由于教程中使用了C++11,所以必须使用VIM7.4 以上的版本才能正常显示C++11中的一些语法(lambda).
视频中采用的是VIM8.1,链接地址 ftp://ftp.vim.org/pub/vim/unix/vim-8.1.tar.bz2
#安装依赖
yum install wget
yum install ncurses-devel
yum install gcc gcc-c++
yum install ctags
yum install bzip2
wget ftp://ftp.vim.org/pub/vim/unix/vim-8.1.tar.bz2
tar xvf vim-8.1.tar.bz2
cd vim81
./configure --prefix=/apps/sylar
make -j4
make install
#验证安装成功
which vim
/apps/sylar/bin/vim
git clone https://github.com/sylar-yin/myvim.git
cp myvim/.vim ~/ -rf
cp myvim/.vimrc ~/
alias vctags="ctags -R --c++-kinds=+p --fields=+iaS --extra=+q"
#添加到/etc/profile末尾
视频中的我使用的VIM配置github路径:https://github.com/sylar-yin/myvim
GCC安装
视频中使用的GCC为最新的稳定版本9.1
完整支持C++11,C++14,C++17,而且错误提示更友好
链接地址:http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-9.1.0/gcc-9.1.0.tar.xz
安装bison
没有安装bison,编译中会提示 “WARNING: ‘bison’ is missing on your system.”
sudo yum install bison
安装texinfo
没有安装texinfo,编译中会提示“WARNING: ‘makeinfo’ is missing on your system”
sudo yum install texinfo
将自定义安装路径添加到PATH
这里我将视频中要用到的程序都安装到一个自定义路径,不会与系统路径冲突。可以多版本并存。
需要将自定义的路径加入到PATH中
export PATH=/apps/sylar/bin:$PATH
export LD_LIBRARY_PATH=/apps/sylar/lib:/apps/sylar/lib64:$LD_LIBRARY_PATH
将这条语句添加到~/.profile 或者 /etc/profile 文件最后。
执行source ~/.profile 或者 source /etc/profile
(我的自定义路径是/apps/sylar)
安装autoconf
gcc安装需要依赖automake-1.15以上版本,automake-1.15以上版本,需要依赖autoconf 2.69
下载地址:http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
tar xvf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure --prefix=/apps/sylar
make -j4
make install
#验证安装成功
which autoconf
/apps/sylar/bin/autoconf
安装automake
gcc安装需要依赖automake-1.15以上版本
下载地址:http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz
wget http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz
tar xvf automake-1.15.tar.gz
cd automake-1.15
./configure --prefix=/apps/sylar
#修改Makefile 查找 /doc/automake-$(APIVERSION)
#doc/automake-$(APIVERSION).1: $(automake_script) lib/Automake/Config.pm
# $(update_mans) automake-$(APIVERSION) --no-discard-stderr
#(3686行,加上--no-discard-stderr)
make -j4
make install
#验证安装成功
which automake
/apps/sylar/bin/automake
GCC正式安装
GCC安装的时间会比较长,大概半小时-2小时,取决于机器性能,需要耐心等待
wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-9.1.0/gcc-9.1.0.tar.xz
tar xvJf gcc-9.1.0.tar.xz
cd gcc-9.1.0
sh contrib/download_prerequisites
mkdir build
cd build
../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib --prefix=/apps/sylar
make -j4
make install
#验证安装成功
which gcc
/apps/sylar/bin/gcc
GDB安装
linux下调试工具, 版本8.3
由于8.3版本需要依赖gcc支持c++11,gdb必须等gcc安装完之后再安装
下载地址:http://ftp.gnu.org/gnu/gdb/gdb-8.3.tar.xz
wget http://ftp.gnu.org/gnu/gdb/gdb-8.3.tar.xz
tar xvf gdb-8.3.tar.xz
cd gdb-8.3
./configure --prefix=/apps/sylar
make -j4
make install
#验证安装成功
which gdb
/apps/sylar/bin/gdb
CMake安装
我使用的版本是CMake3.14.5
下载地址:https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5.tar.gz
wget https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5.tar.gz
tar xvf cmake-3.14.5.tar.gz
cd cmake-3.14.5
./configure --prefix=/apps/sylar
make -j4
make install
#验证安装成功
which cmake
/apps/sylar/bin/cmake
Ragel安装
有限状态机,编写出来的协议解析性能不弱于汇编
我使用的版本是Ragel 6.10,
下载地址:http://www.colm.net/files/ragel/ragel-6.10.tar.gz
wget http://www.colm.net/files/ragel/ragel-6.10.tar.gz
tar xvf ragel-6.10.tar.gz
cd ragel-6.10
./configure --prefix=/apps/sylar
make -j4
make install
#验证安装成功
which ragel
/apps/sylar/bin/ragel
boost安装
yum install boost-devel
其他
#killall 安装
yum install psmisc
#openssl 安装
yum install openssl-devel
#netstat 安装
yum install net-tools
大佬,环境都装完了,用你的工程make出问题了
— You will link dynamically to the MySQL client library (set with -DMYSQLCLIENT_STATIC_LINKING=)
— Searching for dynamic libraries with the base name(s) “mysqlclient_r mysqlclient”
— mysql_config was found /usr/bin/mysql_config
— MySQL client environment/cmake variables set that the user can override
— MYSQL_DIR :
— MYSQL_INCLUDE_DIR : /usr/include/mysql
— MYSQL_LIB_DIR : /usr/lib64/mysql
— MYSQL_CONFIG_EXECUTABLE : /usr/bin/mysql_config
— MYSQL_CXX_LINKAGE : 1
— MYSQL_CFLAGS : -I/usr/include/mysql -m64
— MYSQL_CXXFLAGS : -I/usr/include/mysql -m64
— MYSQLCLIENT_STATIC_LINKING :
— MYSQLCLIENT_NO_THREADS :
— MySQL client optional environment/cmake variables set by the user
— MYSQL_EXTRA_LIBRARIES :
— MYSQL_LINK_FLAGS :
— MySQL client settings that the user can’t override
— MYSQL_VERSION : 8.0.17
— MYSQL_VERSION_ID : 80017
— MYSQL_LIB : /usr/lib64/mysql/libmysqlclient.so
— MYSQL_LIBRARIES : mysqlclient;pthread;m;rt;ssl;crypto;dl
— Could NOT find Protobuf (missing: Protobuf_INCLUDE_DIR)
— Found OpenSSL: /usr/lib64/libcrypto.so (found version “1.0.2k”)
— Found ZLIB: /usr/lib64/libz.so (found version “1.2.7”)
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
Protobuf_LIBRARY
linked by target “test_email” in directory /home/darren/workspace/sylar
linked by target “test_sqlite3” in directory /home/darren/workspace/sylar
linked by target “bin_sylar” in directory /home/darren/workspace/sylar
linked by target “test_rock” in directory /home/darren/workspace/sylar
linked by target “test_nameserver” in directory /home/darren/workspace/sylar
linked by target “test_mysql” in directory /home/darren/workspace/sylar
linked by target “orm” in directory /home/darren/workspace/sylar
linked by target “test_crypto” in directory /home/darren/workspace/sylar
— Configuring incomplete, errors occurred!
See also “/home/darren/workspace/sylar/build/CMakeFiles/CMakeOutput.log”.
See also “/home/darren/workspace/sylar/build/CMakeFiles/CMakeError.log”.
make: *** [xx] 错误 1
少了没有安装protobuf库