最近工作需要在Mac机上使用thrift0.9.2,但是使用brew怎么安装都失败。最后摸索除了一条比较复杂的道路,但是终于走通了。
安装前置依赖
1 | brew install boost |
下载thrift源码包
路径为:https://github.com/apache/thrift/releases/tag/0.9.2,下载tar.gz版本
编译
1 | ./configure --prefix=/usr/local/thrift/ --disable-static --with-boost=/usr/local/Cellar/boost/1.72.0/ --with-libevent=/usr/local/Cellar/libevent/2.1.11_1/ --without-python --without-csharp --without-ruby --without-perl --without-php --without-haskell --without-erlang LDFLAGS='-L/usr/local/opt/openssl/lib' CPPFLAGS='-I/usr/local/opt/openssl/include' CXXFLAGS="-std=c++11" |
编译过程中会出现不少错误,下面列出错误的解决方法:
- processor/ProcessorTest.cpp:26:10: fatal error: 'tr1/functional' file not found。原因:boost库的头文件找不到。 解决办法:更改代码为include
- ld: library not found for -l:libboost_unit_test_framework.a。原因:boost中库找不到。解决办法:将对应文件lib/cpp/test/Makefile中的 -l:libboost_unit_test_framework.a改为/usr/local/Cellar/boost/1.72.0/lib/libboost_unit_test_framework.a,这里以电脑上boost的库目录为准
- thrift/serializer_types.go:271:10: Errorf format %s reads arg #1, but call has 0 args。原因:go的测试用例失败,根据错误提示手动更改格式化类型,或者直接不输出。
- error: non-void function 't_test_thrift_test_handler_test_void' should return a value。原因:go的测试用例和cglib版本有冲突,导致有一些函数没有返回值。解决办法:直接return TRUE; 并且屏蔽之前的代码。这里是测试用例,不影响编译结果,全代码中这个错误得有几十个。
- package code.google.com/p/gomock/gomock: unrecognized import path "code.google.com/p/gomock/gomock"。原因:找不到code.google.com里面有这个包。解决方法:替换test/go/Makefile.in中的code.google.com/p/gomock/gomock为github.com/golang/mock/gomock,对文件test/go/src/common/mock_handler.go做同样修改。
解决了这些问题后,thrift0.9.2编译安装成功,目录在/usr/local/thrift下。但是这里面除了前两个错误其他都是测试用例的错误,其实不影响最终的二进制生成。我尝试不管make的错误,直接执行make install,仍然得到了一个可用的thrift0.9.2二进制。希望我踩的一些坑对你有帮助。