Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8139389
  • 博文数量: 594
  • 博客积分: 13065
  • 博客等级: 上将
  • 技术积分: 10324
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-26 16:44
个人简介

推荐: blog.csdn.net/aquester https://github.com/eyjian https://www.cnblogs.com/aquester http://blog.chinaunix.net/uid/20682147.html

文章分类

全部博文(594)

分类: C/C++

2013-01-07 15:28:07


背景:
当在使用thrift时,如果我们的代码也采用automake方式编译,这样就存在config.h文件冲突,原因是thrift的Thread.h文件include它时,没有目录修饰。


config.h:
在成功编译thrift后,会在它的thrift目录下生成一个config.h文件,这个文件实际是由automake产生的,如下所示 :


> ls thrift
async        config.h   protocol  server                   TDispatchProcessor.h  TLogging.h    transport
concurrency  processor  qt        TApplicationException.h  Thrift.h              TProcessor.h  TReflectionLocal.h



concurrency/Thread.h:
在Thread.h头文件中会包含这个头文件,遗憾的是Thread.h是对外的公共文件,也就是使用thrift会直接看到它,而config.h被include时,未加任何目录修饰,这就是收到大量编译警告的原因。


#ifdef HAVE_CONFIG_H
#include
#endif


ERROR MESSAGE:
需要将Thread.h中的#include 注释掉,下面的大量编译警告即可消息,而且thrift编译也没有问题。


make[2]: Entering directory `@_@'
if g++ -DHAVE_CONFIG_H -I. -I. -I../.. -I../.. -I../../../third-party/boost/include -I../../../third-party/thrift/include -I../../../third-party/sqlite/include -I../../../third-party/gflags/include -I../../../third-party/glog/include -I../../../third-party/libevent/include -I../../../third-party/mysql/include    -D_GNU_SOURCE -rdynamic -Wall -fPIC -g -MT ExecutorService_server.skeleton.o -MD -MP -MF ".deps/ExecutorService_server.skeleton.Tpo" -c -o ExecutorService_server.skeleton.o `test -f './ExecutorService_server.skeleton.cpp' || echo './'`./ExecutorService_server.skeleton.cpp; \
then mv -f ".deps/ExecutorService_server.skeleton.Tpo" ".deps/ExecutorService_server.skeleton.Po"; else rm -f ".deps/ExecutorService_server.skeleton.Tpo"; exit 1; fi
In file included from ../../../third-party/thrift/include/thrift/concurrency/Thread.h:28,
                 from ../../../third-party/thrift/include/thrift/server/TServer.h:26,
                 from ../../../third-party/thrift/include/thrift/server/TSimpleServer.h:23,
                 from ./ExecutorService_server.skeleton.cpp:6:
../../config.h:44:1: warning: "PACKAGE" redefined
In file included from ../../../third-party/thrift/include/thrift/TLogging.h:24,
                 from ../../../third-party/thrift/include/thrift/Thrift.h:51,
                 from ../../../third-party/thrift/include/thrift/transport/TTransport.h:23,
                 from ../../../third-party/thrift/include/thrift/protocol/TProtocol.h:23,
                 from ../../../third-party/thrift/include/thrift/TProcessor.h:24,
                 from ../../../third-party/thrift/include/thrift/TDispatchProcessor.h:22,
                 from ./ExecutorService.h:10,
                 from ./ExecutorService_server.skeleton.cpp:4:
../../../third-party/thrift/include/thrift/config.h:263:1: warning: this is the location of the previous definition
In file included from ../../../third-party/thrift/include/thrift/concurrency/Thread.h:28,
                 from ../../../third-party/thrift/include/thrift/server/TServer.h:26,
                 from ../../../third-party/thrift/include/thrift/server/TSimpleServer.h:23,
                 from ./ExecutorService_server.skeleton.cpp:6:
../../config.h:47:1: warning: "PACKAGE_BUGREPORT" redefined
In file included from ../../../third-party/thrift/include/thrift/TLogging.h:24,
                 from ../../../third-party/thrift/include/thrift/Thrift.h:51,
                 from ../../../third-party/thrift/include/thrift/transport/TTransport.h:23,
                 from ../../../third-party/thrift/include/thrift/protocol/TProtocol.h:23,
                 from ../../../third-party/thrift/include/thrift/TProcessor.h:24,
                 from ../../../third-party/thrift/include/thrift/TDispatchProcessor.h:22,
                 from ./ExecutorService.h:10,
                 from ./ExecutorService_server.skeleton.cpp:4:
../../../third-party/thrift/include/thrift/config.h:266:1: warning: this is the location of the previous definition
In file included from ../../../third-party/thrift/include/thrift/concurrency/Thread.h:28,
                 from ../../../third-party/thrift/include/thrift/server/TServer.h:26,
                 from ../../../third-party/thrift/include/thrift/server/TSimpleServer.h:23,
                 from ./ExecutorService_server.skeleton.cpp:6:
../../config.h:50:1: warning: "PACKAGE_NAME" redefined
In file included from ../../../third-party/thrift/include/thrift/TLogging.h:24,
                 from ../../../third-party/thrift/include/thrift/Thrift.h:51,
                 from ../../../third-party/thrift/include/thrift/transport/TTransport.h:23,
                 from ../../../third-party/thrift/include/thrift/protocol/TProtocol.h:23,
                 from ../../../third-party/thrift/include/thrift/TProcessor.h:24,
                 from ../../../third-party/thrift/include/thrift/TDispatchProcessor.h:22,
                 from ./ExecutorService.h:10,
                 from ./ExecutorService_server.skeleton.cpp:4:
../../../third-party/thrift/include/thrift/config.h:269:1: warning: this is the location of the previous definition
In file included from ../../../third-party/thrift/include/thrift/concurrency/Thread.h:28,
                 from ../../../third-party/thrift/include/thrift/server/TServer.h:26,
                 from ../../../third-party/thrift/include/thrift/server/TSimpleServer.h:23,
                 from ./ExecutorService_server.skeleton.cpp:6:
../../config.h:53:1: warning: "PACKAGE_STRING" redefined
In file included from ../../../third-party/thrift/include/thrift/TLogging.h:24,
                 from ../../../third-party/thrift/include/thrift/Thrift.h:51,
                 from ../../../third-party/thrift/include/thrift/transport/TTransport.h:23,
                 from ../../../third-party/thrift/include/thrift/protocol/TProtocol.h:23,
                 from ../../../third-party/thrift/include/thrift/TProcessor.h:24,
                 from ../../../third-party/thrift/include/thrift/TDispatchProcessor.h:22,
                 from ./ExecutorService.h:10,
                 from ./ExecutorService_server.skeleton.cpp:4:
../../../third-party/thrift/include/thrift/config.h:272:1: warning: this is the location of the previous definition
In file included from ../../../third-party/thrift/include/thrift/concurrency/Thread.h:28,
                 from ../../../third-party/thrift/include/thrift/server/TServer.h:26,
                 from ../../../third-party/thrift/include/thrift/server/TSimpleServer.h:23,
                 from ./ExecutorService_server.skeleton.cpp:6:
../../config.h:56:1: warning: "PACKAGE_TARNAME" redefined
In file included from ../../../third-party/thrift/include/thrift/TLogging.h:24,
                 from ../../../third-party/thrift/include/thrift/Thrift.h:51,
                 from ../../../third-party/thrift/include/thrift/transport/TTransport.h:23,
                 from ../../../third-party/thrift/include/thrift/protocol/TProtocol.h:23,
                 from ../../../third-party/thrift/include/thrift/TProcessor.h:24,
                 from ../../../third-party/thrift/include/thrift/TDispatchProcessor.h:22,
                 from ./ExecutorService.h:10,
                 from ./ExecutorService_server.skeleton.cpp:4:
../../../third-party/thrift/include/thrift/config.h:275:1: warning: this is the location of the previous definition
In file included from ../../../third-party/thrift/include/thrift/concurrency/Thread.h:28,
                 from ../../../third-party/thrift/include/thrift/server/TServer.h:26,
                 from ../../../third-party/thrift/include/thrift/server/TSimpleServer.h:23,
                 from ./ExecutorService_server.skeleton.cpp:6:
../../config.h:59:1: warning: "PACKAGE_VERSION" redefined
In file included from ../../../third-party/thrift/include/thrift/TLogging.h:24,
                 from ../../../third-party/thrift/include/thrift/Thrift.h:51,
                 from ../../../third-party/thrift/include/thrift/transport/TTransport.h:23,
                 from ../../../third-party/thrift/include/thrift/protocol/TProtocol.h:23,
                 from ../../../third-party/thrift/include/thrift/TProcessor.h:24,
                 from ../../../third-party/thrift/include/thrift/TDispatchProcessor.h:22,
                 from ./ExecutorService.h:10,
                 from ./ExecutorService_server.skeleton.cpp:4:
../../../third-party/thrift/include/thrift/config.h:281:1: warning: this is the location of the previous definition
In file included from ../../../third-party/thrift/include/thrift/concurrency/Thread.h:28,
                 from ../../../third-party/thrift/include/thrift/server/TServer.h:26,
                 from ../../../third-party/thrift/include/thrift/server/TSimpleServer.h:23,
                 from ./ExecutorService_server.skeleton.cpp:6:
../../config.h:65:1: warning: "VERSION" redefined
In file included from ../../../third-party/thrift/include/thrift/TLogging.h:24,
                 from ../../../third-party/thrift/include/thrift/Thrift.h:51,
                 from ../../../third-party/thrift/include/thrift/transport/TTransport.h:23,
                 from ../../../third-party/thrift/include/thrift/protocol/TProtocol.h:23,
                 from ../../../third-party/thrift/include/thrift/TProcessor.h:24,
                 from ../../../third-party/thrift/include/thrift/TDispatchProcessor.h:22,
                 from ./ExecutorService.h:10,
                 from ./ExecutorService_server.skeleton.cpp:4:
../../../third-party/thrift/include/thrift/config.h:327:1: warning: this is the location of the previous definition
阅读(4145) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

Aquester2017-02-08 14:30:31

Aquester:64位机器上编译,遇到如下链接错误,依赖的thrift为thrift-0.9.0:
/bin/ld: /usr/local/thrift/lib/libthrift.a(Thrift.o): relocation R_X86_64_32S against `_ZNSs4_Rep20_S_empty_rep_storageE\' can not be used when making a shared object; recompile with -fPIC
/usr/local/thrift/lib/libthrift.a: could not read symbols: 错误的值

解决办法:设置CXXFLAGS,加上-fPIC,重编译thrift,但注意不能是CPPFLAGS,如下所示
 ./configure --prefix=/usr/local/thrift-0.9.0 --with-boost=/usr/local/boost --with-libevent=/us

如下所示的链接错误,可采取同样的方法重编译protobuf,依赖的protobuf为protobuf-2.6.1
/bin/ld: /usr/local/protobuf/lib/libprotobuf.a(common.o): relocation R_X86_64_32S against `_ZTVN6google8protobuf7ClosureE\' can not be used when making a shared object; recompile with -fPIC
/usr/local/protobuf/lib/libprotobuf.a: could not read symbols: 错误的值

重编译protobuf:
./configure --prefix=/usr/local/protobuf-2.6.1 --with-zlib CXXFLAGS=\"-fPIC\"
注意configure后要做下make cle

回复 | 举报

Aquester2017-02-08 14:27:39

64位机器上编译,遇到如下链接错误,依赖的thrift为thrift-0.9.0:
/bin/ld: /usr/local/thrift/lib/libthrift.a(Thrift.o): relocation R_X86_64_32S against `_ZNSs4_Rep20_S_empty_rep_storageE\' can not be used when making a shared object; recompile with -fPIC
/usr/local/thrift/lib/libthrift.a: could not read symbols: 错误的值

解决办法:设置CXXFLAGS,加上-fPIC,重编译thrift,但注意不能是CPPFLAGS,如下所示
 ./configure --prefix=/usr/local/thrift-0.9.0 --with-boost=/usr/local/boost --with-libevent=/us