zthread库(version 2.3.2)在gcc 3.4.2下编译问题的解决方法

转自:

http://blog.sina.com.cn/s/blog_591f0e6e010008o7.html

http://www.cnblogs.com/moodlxs/archive/2012/10/16/2725329.html


zthread库简介

ZThread库是一个开源的跨平台高级面向对象的线程和synchronization 库,以运行POSIX 和Win32 系统中的C++程序。

ZThread库的主页:http://zthread.sourceforge.net

最新版本Zthread源码下载地址: http://prdownloads.sourceforge.net/zthread/ZThread-2.3.2.tar.gz

ZThread文档:http://zthread.sourceforge.net/documentation.html


问题描述

zthread库(version 2.3.2)在gcc 3.4.2下编译,错误提示如下

g++ -DHAVE_CONFIG_H -I. -I. -I. -I../include -g -O2 -Wall -DNDEBUG -g -O2 -Wall -DNDEBUG -MT AtomicCount.lo -MD -MP -MF .deps/AtomicCount.Tpo -c AtomicCount.cxx  -fPIC -DPIC -o .libs/AtomicCount.o
In file included from vanilla/SimpleAtomicCount.cxx:26,
                 from AtomicCount.cxx:55:
../include/zthread/Guard.h: In destructor `ZThread::Guard<LockType, LockingPolicy>::~Guard()':
../include/zthread/Guard.h:494: error: there are no arguments to `isDisabled' that depend on a template parameter, so a declaration of `isDisabled' must be available
../include/zthread/Guard.h:494: error: (if you use `-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)


问题分析

查看include/zthread/guard.h, 模板类Guard<LockType, LockingPolicy> 私有继承于 private LockHolder<LockType>, private NonCopyable;
而模板类LockHolder<LockType>中提供了isDisabled()方法啊,为什么编译器不识别呢?(GNU gcc/g++版本的问题?)

这个是编译器编译器版本的问题.印象里Zthread的作者已经停止开发一段时间了.

g++3.4以后版本的名字查找方法和以前的版本不同,问题这里有解释:http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html意思就是说:

虽然类Guard<LockType, LockingPolicy> 私有继承于 private LockHolder<LockType>,并且模板类LockHolder<LockType>中提供了isDisabled()方法。但是,由于g++ 在以后3.4以后就不能找到父类模板类中的 isDisabled()方法了,同时zthread库没有与时俱进做些修改,导致用新版本的g++编译失败。


解决方法

简而言之,3.4以后版本的g++查找名字时,对于模板类中对基类方法或者基类的成员变量的调用,如果该基类方法或者基类成员变量与模板参数类型(typename T)无关

方法一:

需要使用this-> 调用或者在类定义中声明using BaseClass<T>::function()

方法二:(参考

先export CXXFLAGS=-fpermissive,然后再执行

./configure

make

make install


方法一对zthread 2.3.2的修改

1)include/zthread/Guard.h

494     if(!this->isDisabled())
2) src/MutexImpl.h

156       this->ownerAcquired(self);
167       this->waiterArrived(self);
176       this->waiterDeparted(self);
195           this->ownerAcquired(self);
239       this->ownerAcquired(self);
256         this->waiterArrived(self);
265         this->waiterDeparted(self);
287           this->ownerAcquired(self);
329     this->ownerReleased(impl);


【yasi】make install之后,zthread的库文件位于

/usr/local/lib/libZThread.so

/usr/local/lib/libZThread.a

头文件位于

/usr/local/include/zthread


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值