運行環(huán)境:Mac
服務器:asio_kcp
編譯直接執(zhí)行主目錄下的allmake.sh文件蜓席,不過編譯前需要安裝一些依賴庫橄教。
依賴庫:
$ ./bootstrap.sh
#服務器引用的mt庫,需要指定下編譯多線程庫
$ sudo ./b2 --layout=tagged threading=multi install
-
Protobuf3.5.0
編譯和安裝參考自帶的README.md
$ sudo brew install autoconf automake libtool curl make g++ unzip
$ ./autogen.sh
$ ./configure
$ make
$ make check
$ sudo make install
-
Muduo
asio_kcp項目third_party目錄下自帶muduo壓縮包礁芦,解壓后堂氯,先打上mac的diff patch。
$ patch -p1 < MacOSX.diff
然后修改muduo/CMakeLists.txt文件
CXX_FLAGS中添加下面兩行:
-D__GXX_EXPERIMENTAL_CXX0X__
-std=c++11
注釋掉 -march=native
注釋掉 -Werror
注釋掉 set(CMAKE_CXX_COMPILER "clang++")
然后在muduo目錄下執(zhí)行:
$ CC=gcc CXX=g++ BUILD_DIR=./build BUILD_TYPE=release BUILD_NO_EXAMPLES=1 . ./build.sh
編譯完成
-
g2log/gmock/gtest
可以直接修改third_party目錄下的build.sh文件進行編譯左电,注意muduo庫最好按照上面的步驟單獨編譯廉侧。
可選庫:
$ make static dynamic cryptest.exe
有個比較方便的管道Pipelining模式连舍,所有新建的對象會傳遞到上級filter没陡,然后由其負責銷毀。比如MD5編碼可以參考如下寫法:
// Memory malloc/free detail see: https://www.cryptopp.com/wiki/Pipelining
static std::string EncodeMD5(const std::string &strIn)
{
std::string digest;
CryptoPP::Weak::MD5 md5;
CryptoPP::StringSource(strIn, true,
new CryptoPP::HashFilter(md5,
new CryptoPP::HexEncoder(
new CryptoPP::StringSink(digest), false)));
return digest;
}
-
Json庫RapidJSON
沒啥說的索赏,鵝廠出品盼玄,戰(zhàn)神制作組都在用。如果不在意速度潜腻,可以試下nlohmann_json埃儿,易用度更接近c++11和腳本語言。 -
日志庫spdlog
速度和易用性都還不錯融涣,還帶Console輸出各種顏色和格式童番。