cygwin上编译RPC框架thrift
cygwin的配置就不多说了,缺什么就通过安装器安装好了。
在thrift的官网下载 thrift-0.11.0源码,通过cmake编译,生成Makefile之后,make出现编译错误
/cygdrive/d/work/thrift-0.11./mybuild $ make [ %] Building CXX object compiler/cpp/CMakeFiles/parse.dir/thrift/thrifty.cc.o
/cygdrive/d/work/thrift-0.11./compiler/cpp/src/thrift/thrifty.yy: 在函数‘int yyparse()’中:
/cygdrive/d/work/thrift-0.11./compiler/cpp/src/thrift/thrifty.yy::: 错误:‘strdup’在此作用域中尚未声明
$$ = strdup("");
^~~~
/cygdrive/d/work/thrift-0.11./compiler/cpp/src/thrift/thrifty.yy::: 附注:suggested alternative: ‘strcmp’
$$ = strdup("");
^~~~
strcmp
make[]: *** [compiler/cpp/CMakeFiles/parse.dir/build.make::compiler/cpp/CMakeFiles/parse.dir/thrift/thrifty.cc.o] 错误
make[]: *** [CMakeFiles/Makefile2::compiler/cpp/CMakeFiles/parse.dir/all] 错误
make: *** [Makefile::all] 错误
查看cmake生成Makefile的日志,在某个cmake文件里设置了-std=c++11,找到:
D:\work\thrift-0.11.0\build\cmake\DefineCMakeDefaults.cmake (2 hits)
Line 79: message(STATUS "Setting C++98 as the default language level (for an older MSVC compiler).")
Line 82: message(STATUS "Setting C++11 as the default language level.")
如下修改:
if (NOT DEFINED CMAKE_CXX_STANDARD)
if (MSVC AND MSVC_VERSION LESS )
# MSVC and earlier don't support template aliases so you have to use C++98
set(CMAKE_CXX_STANDARD )
message(STATUS "Setting C++98 as the default language level (for an older MSVC compiler).")
else()
#set(CMAKE_CXX_STANDARD ) # C++
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
message(STATUS "Setting C++11 as the default language level.")
endif()
message(STATUS "To specify a different C++ language level, set CMAKE_CXX_STANDARD")
endif()
继续编译,随即遇到编译错误:
[ %] Building CXX object lib/cpp/CMakeFiles/thrift_static.dir/src/thrift/transport/THttpServer.cpp.o
/cygdrive/d/work/thrift-0.11./lib/cpp/src/thrift/transport/THttpServer.cpp: 在成员函数‘virtual void apache::thrift::transport::THttpServer::parseHeader(char*)’中:
/cygdrive/d/work/thrift-0.11./lib/cpp/src/thrift/transport/THttpServer.cpp::: 错误:‘strcasestr’在此作用域中尚未声明
#define THRIFT_strcasestr(haystack, needle) strcasestr(haystack, needle)
^
/cygdrive/d/work/thrift-0.11./lib/cpp/src/thrift/transport/THttpServer.cpp::: 附注:in expansion of macro ‘THRIFT_strcasestr’
if (THRIFT_strcasestr(value, "chunked") != NULL) {
^~~~~~~~~~~~~~~~~
/cygdrive/d/work/thrift-0.11./lib/cpp/src/thrift/transport/THttpServer.cpp::: 附注:suggested alternative: ‘strcasecmp’
#define THRIFT_strcasestr(haystack, needle) strcasestr(haystack, needle)
^
/cygdrive/d/work/thrift-0.11./lib/cpp/src/thrift/transport/THttpServer.cpp::: 附注:in expansion of macro ‘THRIFT_strcasestr’
if (THRIFT_strcasestr(value, "chunked") != NULL) {
^~~~~~~~~~~~~~~~~
make[]: *** [lib/cpp/CMakeFiles/thrift_static.dir/build.make::lib/cpp/CMakeFiles/thrift_static.dir/src/thrift/transport/THttpServer.cpp.o] 错误
make[]: *** [CMakeFiles/Makefile2::lib/cpp/CMakeFiles/thrift_static.dir/all] 错误
make: *** [Makefile::all] 错误
这里我就直接修改源代码了:
#define _GNU_SOURCE
#include <string.h>
将这两行放在thrift-0.11.0/lib/cpp/src/thrift/transport/THttpServer.cpp的其他include头文件的前面,不然 #define _GNU_SOURCE 会被编译器忽略
随即又遇到编译错误:
/cygdrive/d/work/thrift-0.11./lib/cpp/src/thrift/concurrency/Mutex.cpp: 在静态成员函数‘static void apache::thrift::concurrency::Mutex::RECURSIVE_INITIALIZER(void*)’中:
/cygdrive/d/work/thrift-0.11./lib/cpp/src/thrift/concurrency/Mutex.cpp::: 错误:‘PTHREAD_MUTEX_RECURSIVE_NP’在此作用域中尚未声明
init_with_kind((pthread_mutex_t*)arg, PTHREAD_MUTEX_RECURSIVE_NP);
^~~~~~~~~~~~~~~~~~~~~~~~~~
/cygdrive/d/work/thrift-0.11./lib/cpp/src/thrift/concurrency/Mutex.cpp::: 附注:suggested alternative: ‘PTHREAD_MUTEX_RECURSIVE’
init_with_kind((pthread_mutex_t*)arg, PTHREAD_MUTEX_RECURSIVE_NP);
^~~~~~~~~~~~~~~~~~~~~~~~~~
PTHREAD_MUTEX_RECURSIVE
make[]: *** [lib/cpp/CMakeFiles/thrift_static.dir/build.make::lib/cpp/CMakeFiles/thrift_static.dir/src/thrift/concurrency/Mutex.cpp.o] 错误
make[]: *** [CMakeFiles/Makefile2:
这里又是cygwin的库问题了,不支持PTHREAD_MUTEX_RECURSIVE_NP,改成 PTHREAD_MUTEX_RECURSIVE
#ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
void Mutex::RECURSIVE_INITIALIZER(void* arg) {
//init_with_kind((pthread_mutex_t*)arg, PTHREAD_MUTEX_RECURSIVE_NP);
init_with_kind((pthread_mutex_t*)arg, PTHREAD_MUTEX_RECURSIVE);
}
#endif
链接单元测试时又出现库不兼容的问题。。。
CMakeFiles/UnitTests.dir/concurrency/MutexTest.cpp.o:MutexTest.cpp:(.rdata$.refptr._ZN6apache6thrift11concurrency5Mutex20ADAPTIVE_INITIALIZEREPv[.refptr._ZN6apache6thrift11concurrency5Mutex20ADAPTIVE_INITIALIZEREPv]+0x0):对‘apache::thrift::concurrency::Mutex::ADAPTIVE_INITIALIZER(void*)’未定义的引用
collect2: 错误:ld 返回
make[]: *** [lib/cpp/test/CMakeFiles/UnitTests.dir/build.make::bin/UnitTests.exe] 错误
make[]: *** [CMakeFiles/Makefile2::lib/cpp/test/CMakeFiles/UnitTests.dir/all] 错误
make: *** [Makefile::all] 错误
自适应锁在cygwin的最新版是没有的,就给它弄个默认的,该咋死咋死吧:
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
void Mutex::ADAPTIVE_INITIALIZER(void* arg) {
// From mysql source: mysys/my_thr_init.c
// Set mutex type to "fast" a.k.a "adaptive"
//
// In this case the thread may steal the mutex from some other thread
// that is waiting for the same mutex. This will save us some
// context switches but may cause a thread to 'starve forever' while
// waiting for the mutex (not likely if the code within the mutex is
// short).
init_with_kind((pthread_mutex_t*)arg, PTHREAD_MUTEX_ADAPTIVE_NP);
}
#else
void Mutex::ADAPTIVE_INITIALIZER(void* arg) {
// From mysql source: mysys/my_thr_init.c
// Set mutex type to "fast" a.k.a "adaptive"
//
// In this case the thread may steal the mutex from some other thread
// that is waiting for the same mutex. This will save us some
// context switches but may cause a thread to 'starve forever' while
// waiting for the mutex (not likely if the code within the mutex is
// short).
init_with_kind((pthread_mutex_t*)arg, PTHREAD_MUTEX_NORMAL);
}
#endif
OK,至此,完美编译成功!
cygwin上编译RPC框架thrift的更多相关文章
- RPC框架Thrift例子-PHP调用C++后端程序
更新 2016-02-22: Response对象不用主动创建. 前言 前段时间用了一下Facebook的开源RPC框架Thrift,做PHP客户端调用C++后端程序,真心觉得Thrift不错! 本文 ...
- rpc框架: thrift/avro/protobuf 之maven插件生成java类
thrift.avro.probobuf 这几个rpc框架的基本思想都差不多,先定义IDL文件,然后由各自的编译器(或maven插件)生成目标语言的源代码,但是,根据idl生成源代码这件事,如果每次都 ...
- .Net RPC框架Thrift的用法
关于Thrift 下面是来自百度百科关于Thrift的介绍: thrift是一个软件框架,用来进行可扩展且跨语言的服务的开发.它结合了功能强大的软件堆栈和引擎,以构建在 C++, Java, Go ...
- rpc框架thrift
跨语言的rpc框架 新建一个thrift文件 # ping service demoservice PingService { string ping(), ping函数的返回类型是字符串} serv ...
- [development][thrift] RPC框架 thrift
一: wiki:https://zh.wikipedia.org/wiki/Thrift 二: 来自IBM的介绍:https://www.ibm.com/developerworks/cn/java/ ...
- RPC框架 - thrift 客户端
-------客户端程序 ------ 下载 下载 thrift 源代码包 下载 thrift 的bin包 准备描述文件(使用源代码包的示例文件) \thrift-0.10.0\tu ...
- RPC框架 - thrift 服务端
-------服务端程序 ------ 下载 下载 thrift 源代码包 下载 thrift 的bin包 准备描述文件(使用源代码包的示例文件) \thrift-0.10.0\tu ...
- [源码解析] PyTorch 分布式(17) --- 结合DDP和分布式 RPC 框架
[源码解析] PyTorch 分布式(17) --- 结合DDP和分布式 RPC 框架 目录 [源码解析] PyTorch 分布式(17) --- 结合DDP和分布式 RPC 框架 0x00 摘要 0 ...
- rpc框架之 thrift 学习 1 - 安装 及 hello world
thrift是一个facebook开源的高效RPC框架,其主要特点是跨语言及二进制高效传输(当然,除了二进制,也支持json等常用序列化机制),官网地址:http://thrift.apache.or ...
随机推荐
- ABAP术语-IAC (Internet Application Components)
IAC (Internet Application Components) 原文:http://www.cnblogs.com/qiangsheng/archive/2008/02/20/107455 ...
- LeetCode 翻转链表
基本思路 从元首节点之后每次取一个节点,并将节点接到元首节点前面 代码实现 /** * Definition for singly-linked list. * struct ListNode { * ...
- 表单验证(JQ)
<!DOCTYPE html> <html> <head> <title></title> <meta charset="u ...
- Vue插槽 slot
1. 什么是插槽 插槽slot 是往父组件中插入额外内容,实现组件的复用,一个插槽插入到一个对应的标签中 2. 实例: 一个组件中不允许有两个匿名插槽 </head> <body&g ...
- Mysqldump自定义导出n条记录
很多时候DBA需要导出部分记录至开发.测试环境,因数据量需求较小,如果原库的记录多,且表数量也多,在用mysqldump命令导出时可以添加一个where参数,自定义导出n条记录,而不必全量导出. 示例 ...
- nginx配置SSL证书/强制跳转与非强制跳转
支持强制跳转HTTPS server { listen 80; server_name www.test.com; rewrite ^(.*)$ https://${server_name}$1 pe ...
- Python协程中使用上下文
在Python 3.7中,asyncio 协程加入了对上下文的支持.使用上下文就可以在一些场景下隐式地传递变量,比如数据库连接session等,而不需要在所有方法调用显示地传递这些变量.使用得当的话, ...
- LINQ巩固
LINQ巩固 LINQ过滤运算符 Where 基于谓词函数过滤值 测试例子如下: public class TestModel { public string Name { get; set; } p ...
- codeforces 845A Chess Tourney
参考:https://blog.csdn.net/zhongyuchen/article/details/77478039 #include <iostream> #include < ...
- TCD产品技术参考资料
1.Willis环 https://en.wikipedia.org/wiki/Circle_of_Willis 2.TCD仿真软件 http://www.transcranial.com/index ...