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的更多相关文章

  1. RPC框架Thrift例子-PHP调用C++后端程序

    更新 2016-02-22: Response对象不用主动创建. 前言 前段时间用了一下Facebook的开源RPC框架Thrift,做PHP客户端调用C++后端程序,真心觉得Thrift不错! 本文 ...

  2. rpc框架: thrift/avro/protobuf 之maven插件生成java类

    thrift.avro.probobuf 这几个rpc框架的基本思想都差不多,先定义IDL文件,然后由各自的编译器(或maven插件)生成目标语言的源代码,但是,根据idl生成源代码这件事,如果每次都 ...

  3. .Net RPC框架Thrift的用法

      关于Thrift 下面是来自百度百科关于Thrift的介绍: thrift是一个软件框架,用来进行可扩展且跨语言的服务的开发.它结合了功能强大的软件堆栈和引擎,以构建在 C++, Java, Go ...

  4. rpc框架thrift

    跨语言的rpc框架 新建一个thrift文件 # ping service demoservice PingService { string ping(), ping函数的返回类型是字符串} serv ...

  5. [development][thrift] RPC框架 thrift

    一: wiki:https://zh.wikipedia.org/wiki/Thrift 二: 来自IBM的介绍:https://www.ibm.com/developerworks/cn/java/ ...

  6. RPC框架 - thrift 客户端

    -------客户端程序 ------ 下载    下载 thrift 源代码包    下载 thrift 的bin包 准备描述文件(使用源代码包的示例文件)    \thrift-0.10.0\tu ...

  7. RPC框架 - thrift 服务端

    -------服务端程序 ------ 下载    下载 thrift 源代码包    下载 thrift 的bin包 准备描述文件(使用源代码包的示例文件)    \thrift-0.10.0\tu ...

  8. [源码解析] PyTorch 分布式(17) --- 结合DDP和分布式 RPC 框架

    [源码解析] PyTorch 分布式(17) --- 结合DDP和分布式 RPC 框架 目录 [源码解析] PyTorch 分布式(17) --- 结合DDP和分布式 RPC 框架 0x00 摘要 0 ...

  9. rpc框架之 thrift 学习 1 - 安装 及 hello world

    thrift是一个facebook开源的高效RPC框架,其主要特点是跨语言及二进制高效传输(当然,除了二进制,也支持json等常用序列化机制),官网地址:http://thrift.apache.or ...

随机推荐

  1. foreach, for in, for of 之间的异同

    forEach() 方法用于调用数组的每个元素,并将元素传递给回调函数. 注意: forEach() 对于空数组是不会执行回调函数的. 示例代码: var arr = [4, 9, 16, 25]; ...

  2. [国家集训队]小Z的袜子(莫队,概率)

    题目描述 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命…… 具体来说,小Z把这N只袜子从1到N编 ...

  3. 第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛--F-等式

    链接:https://www.nowcoder.com/acm/contest/90/F 来源:牛客网 1.题目描述 给定n,求1/x + 1/y = 1/n (x<=y)的解数.(x.y.n均 ...

  4. .Net core NPOI导入导出Excel

    最近在想.net core NPOI 导入导出Excel,一开始感觉挺简单的,后来真的遇到很多坑.所以还是写一篇博客让其他人少走一些弯路,也方便忘记了再重温一遍.好了,多的不说,直接开始吧. 在.Ne ...

  5. 表单验证(JQ)

    <!DOCTYPE html> <html> <head> <title></title> <meta charset="u ...

  6. Java处理中文乱码问题

    package servlet; import javax.servlet.*; import javax.servlet.annotation.WebFilter; import javax.ser ...

  7. hive的desc命令

    desc命令 desc 命令是为了展示hive表格的内在属性.例如列名,data_type,存储位置等信息.这个命令常常用在我们对hive表格观察之时,我们想要知道这个hive各个列名(基于这些具体列 ...

  8. [BZOJ1076][SCOI2008]奖励关(概率DP)

    Code #include <cstdio> #include <algorithm> #include <cstring> #define N 110 #defi ...

  9. oracle查询优化,存储过程select表循环插入另一个表,以及索引重建

    查询语句pl/sql中用F5优化语句 ORACLE的explain plan工具的作用只有一个,获取语句的执行计划1.语句本身并不执行,ORACLE根据优化器产生理论上的执行计划2.语句的分析结果存放 ...

  10. P1016 旅行家的预算

    P1016 旅行家的预算 题目描述 一个旅行家想驾驶汽车以最少的费用从一个城市到另一个城市(假设出发时油箱是空的).给定两个城市之间的距离D1.汽车油箱的容量C(以升为单位).每升汽油能行驶的距离D2 ...