rpcz VC2010 建構
rpcz 是應用ZeroMQ和Protobuf開發的RPC.
見: https://github.com/reinferio/rpcz
及 https://code.google.com/p/rpcz/
rpcz的CMake腳本應該是僅用于Linux. 用于VC需要更改錯誤。
CMake Error at D:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1192 (message):
Unable to find the requested Boost libraries.
如果找不到boost_thread庫,添加
SET(Boost_USE_STATIC_LIBS TRUE)
因為Windows下Boost預設是不生成動态庫的。
Required library ZeroMQ NOT FOUND.
Could NOT find PROTOBUF (missing: PROTOBUF_LIBRARY PROTOBUF_INCLUDE_DIR)
可手工在cmake-gui中設定ZeroMQ的INCLUDE_DIR和LIBRARY, 以及protobuf的源碼目錄.
CMake生成sln後, 用VC打開, 建構.
cl : Command line error D8021: invalid numeric argument '/Wextra'
将gcc編譯參數用if包括:
+if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -Werror")
+endif(CMAKE_COMPILER_IS_GNUCXX)
application.cc(18): fatal error C1083: Cannot open include file: 'zmq.hpp': No such file or directory
需要設定 cppzmq 目錄.
添加CPPZMQ_DIR.
或者直接 include_directories(E:/JinQing/Src/cppzmq)
src\rpcz/rpcz.pb.h(293): error C2059: syntax error : 'constant'
生成的代碼 NO_ERROR 與VC Error.h 中的 define 沖突.
改為 APPLICATION_NO_ERROR 常量,不會與宏沖突。
clock.cc
..\..\..\..\LibSrc\rpcz\src\rpcz\clock.cc(18): fatal error C1083: Cannot open include file: 'sys/time.h': No such file or directory
将gettimeofday()改為:
return boost::chrono::high_resolution_clock().now().time_since_epoch().count / 1000000;
connection_manager.cc
..\..\..\..\LibSrc\rpcz\src\rpcz\connection_manager.cc(25): fatal error C1083: Cannot open include file: 'pthread.h': No such file or directory
DELETE
connection_manager.cc
..\..\..\..\LibSrc\rpcz\src\rpcz\connection_manager.cc(28): fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory
改為:
#ifdef WIN32
#include <process.h> // for getpid()
#else
#include <unistd.h> // for getpid()
#endif
..\..\..\..\LibSrc\rpcz\src\rpcz\reactor.cc(122): error C2079: 'action' uses undefined struct 'rpcz::install_signal_handler::sigaction'
..\..\..\..\LibSrc\rpcz\src\rpcz\reactor.cc(125): error C3861: 'sigemptyset': identifier not found
改為:
void install_signal_handler() {
#ifdef WIN32
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
#else
struct sigaction action;
action.sa_handler = signal_handler;
action.sa_flags = 0;
sigemptyset(&action.sa_mask);
sigaction(SIGINT, &action, NULL);
sigaction(SIGTERM, &action, NULL);
#endif // WIN32
}
server.cc
..\..\..\..\LibSrc\rpcz\src\rpcz\server.cc(20): fatal error C1083: Cannot open include file: 'sys/errno.h': No such file or directory
DELETE
zmq_utils.cc
D:/LibSrc/rpcz/include\rpcz/zmq_utils.hpp(58): error C2146: syntax error : missing ';' before identifier 'has_more_'
改為int
------ Build started: Project: rpcz, Configuration: Release Win32 ------
LINK : fatal error LNK1104: cannot open file 'libboost_date_time-vc100-mt-1_53.lib'
Add lib dir.
3>------ Build started: Project: zsendrpc, Configuration: Debug Win32 ------
3> zsendrpc.cc
3>LINK : fatal error LNK1104: cannot open file 'Debug\rpcz.lib'
僅生成rpcz.dll, 沒有lib. 因為沒有export.
應該生成靜态庫.
開啟 rpcz_build_static
并且讓zsendrpc在rpcz.lib之後編譯:
add_dependencies(zsendrpc rpcz_static) # zsendrpc need rpcz.lib
修改後的代碼見:
https://github.com/jinq0123/rpcz