用g ++ 3.0编译 [英] Compiling with g++ 3.0

查看:53
本文介绍了用g ++ 3.0编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码适用于g ++ 2.75但是

我在使用g ++ 3.0进行编译时遇到了一些麻烦。


如果你有一个解决方案。


这是错误信息。


main.hpp:28:专门化`struct std :: hash< std :: string> ;''在不同的

命名空间

/usr/include/g++-v3/ext/stl_hash_fun.h:68:从`template< class
的定义
_Key> struct std :: hash''

make:*** [resource_identifier.lo]错误1

#include< pair.h>

#include< string>

#include< map>

#include< vector>

#ifdef __GNUC__ / *抓住了libstdc ++ faq * /

#if __GNUC__< 3

#include< hash_map.h>

命名空间Sgi {using :: hash_map; }; //继承全局数

#else

#include< \\ text / hash_map>

#if __GNUC_MINOR__ == 0

namespace Sgi = std; // GCC 3.0

#else

命名空间Sgi = :: __ gnu_cxx; // GCC 3.1及更高版本

#endif

#endif

#else // ...还有其他编译器,对吧? />
命名空间Sgi = std;

#endif

使用命名空间std;

// TODO:在此包含此定义Hashtable类

模板<> struct hash< string>

{

size_t operator()(const string& s)const

{

return hash< char const *>()(s.c_str());

}

};

#ifdef NAMESPACES

命名空间foobar {

#endif


class NoSuchElementException

{

public:

NoSuchElementException(string w){_what = w;}

virtual~NoSuchElementException(){}

virtual string what(){ return _what; }

私人:

string _what;

};

template< class T> class Hashtable //:public ost :: Conditional

{

public:

Hashtable(){} //:Conditional(){}


virtual~Hashtable(){clear(); } $ / $
虚拟T put(const字符串&键,T值)

{

assert(key.c_str()!= NULL); // TODO:必须扔?


// enterMutex();

T returnValue = mHashtable [key];

mHashtable [key] = value;

// leaveMutex();


返回returnValue;

}


虚拟T get(const string& key)throw(NoSuchElementException)

{

assert(key.c_str()!= NULL); // TODO:必须扔?

// enterMutex();


if(mHashtable.empty())

{

// leaveMutex();

抛出NoSuchElementException(key);

}


if (mHashtable.find(key)== mHashtable.end())

{

// leaveMutex();

抛出NoSuchElementException(键);

}


T returnValue = mHashtable [key];

// leaveMutex();


返回returnValue;

}

虚拟空白del(const string& key)throw(NoSuchElementException)

{

断言(key.c_str()!= NULL); // TODO:必须抛出?

// enterMutex();


if(mHashtable.find(key)== mHashtable.end()){

// leaveMutex();

抛出NoSuchElementException(key);

}

mHashtable.erase(key );

// leaveMutex();


返回;

}

虚拟无效清除(){

// enterMutex();

mHashtable.erase(mHashtable.begin(),mHashtable.end());

// leaveMutex();

}


虚拟布尔isEmpty(){

bool ret;

// enterMutex();

ret = mHashtable.empty();

// leaveMutex();

返回ret; < br $>
}


虚拟向量< pair< string,T> > toVector()

throw(NoSuchElementException)

{

vector< pair< string,T> > v;

// enterMutex();


if(mHashtable.empty()){

// leaveMutex() ;

抛出NoSuchElementException(字符串(哈希表为空));

}


for(hash_map< string, T,hash< string>> :: iterator iter

= mHashtable.begin(); iter!= mHashtable.end(); ++ iter)

{

pair< string,T> p(* iter); //(iter-> first,iter-> second);

v.insert(v.begin(),p);

}


// leaveMutex();

返回v;

}


protected:

hash_map< string,T,hash< string> > mHashtable;

};


int

main(无效)

{

Hashtable< int> h;


返回0;

}

#ifdef NAMESPACES

}; // foobar

#endif


/ ** EMACS **

*局部变量:

*模式:c ++

* c-basic-offset:4

*结束:

* /


这是我发布的g ++ 3.0:

$ g ++ - 3.0 -v

从/ usr / lib / gcc-lib / i386-linux /读取规范3.0.4 / specs

配置:../ src / configure -v

--enable-languages = c,c ++,java,f77,proto,objc

--prefix = / usr --infodir = / share / info --mandir = / share / mx

线程模型:posix

gcc版本3.0.4


这是我发布的g ++ 2.95:

g ++ -v

从/ usr / lib读取规范/gcc-lib/i386-linux/2.95.4/specs

gcc版本2.95.4 20011002(Debian预发布)


-
Lu*********@cvf.fr

解决方案

g ++ - 3.0 -v

从/usr/lib/gcc-lib/i386-linux/3.0.4/specs阅读规范

配置w ith:../src/configure -v

--enable-languages = c,c ++,java,f77,proto,objc

--prefix = / usr - -infodir = / share / info --mandir = / share / mx

线程模型:posix

gcc版本3.0.4


这是我发布的g ++ 2.95:

g ++ -v

从/usr/lib/gcc-lib/i386-linux/2.95.4/specs阅读规范

gcc版本2.95.4 20011002(Debian预发布)


-
Lu ********* @ cvf.fr


Luc Mazardo写道:

以下代码适用于g ++ 2.75,但是使用g ++ 3.0进行编译时遇到了一些麻烦。

如果您有解决方案,请提前感谢。

这是错误信息。

main.hpp:28:在不同的
命名空间中专门化`struct std :: hash< std :: string>'' br /> /usr/include/g++-v3/ext/stl_hash_fun.h:68:来自`template< class
_Key>的定义struct std :: hash''
make:*** [resource_identifier.lo]错误1


hash_map不是STL的一部分,所以gcc团队(努力要符合
标准,请将hash *模板移动到__gnu_cxx

命名空间。 gcc 3.x系列也更符合标准,所以

你需要修复一些gcc 2.9x的东西。


#include< pair.h>
^^^^^^^^^不需要这个头 - std :: pair在std :: map中找到并且

pair.h是非标准的#include< ; string>
#include< map>
#include< vector>

#ifdef __GNUC__ / *在libstdc ++ faq中获取* /
#if __GNUC__< ; 3
#include< hash_map.h>
命名空间Sgi {using :: hash_map; }; //继承全局数
#else
#include< \\ text / hash_map>
#if __GNUC_MINOR__ == 0
命名空间Sgi = std; // GCC 3.0
#else
命名空间Sgi = :: __ gnu_cxx; // GCC 3.1及更高版本
#endif
#endif
#else // ...还有其他编译器,对吧?
命名空间Sgi = std;
# endif

using namespace std;


使用命名空间__gnu_cxx;

// TODO:在Hashtable类中包含此定义
命名空间__gnu_cxx

{

模板<> struct hash< string>
{
size_t operator()(const string& s)const
{
返回哈希< char const *>()(s.c_str() );
}
};


};

#ifdef NAMESPACES
名称空间foobar {
#endif

class NoSuchElementException
公共:
NoSuchElementException(string w){_what = w;}
virtual~NoSuchElementException(){}
虚拟字符串what(){返回_什么; }
private:
string _what;
};
template< class T> class Hashtable //:public ost :: Conditional
{
public:
Hashtable(){} //:Conditional(){}

virtual~Hashtable( ){clear();虚拟T put(const string& key,T value)
{
assert(key.c_str()!= NULL); // TODO:必须抛出?

// enterMutex();
T returnValue = mHashtable [key];
mHashtable [key] = value;
// leaveMutex();

返回returnValue;
}
虚拟T get(const string& key)throw(NoSuchElementException)

assert(key.c_str()!= NULL); // TODO:必须扔?
// enterMutex();

if(mHashtable.empty())
//
// leaveMutex();
抛出NoSuchElementException(key);
}
if(mHashtable.find(key)== mHashtable.end())
{
// leaveMutex( );
抛出NoSuchElementException(key);
}
T returnValue = mHashtable [key];
// leaveMutex();
return returnValue;
}
virtual void del(const string& key)throw(NoSuchElementException)
{
assert(key.c_str()!= NULL); // TODO:必须扔?
// enterMutex();

if(mHashtable.find(key)== mHashtable.end()){
// leaveMutex( );
抛出NoSuchElementException(key);
}
mHashtable.erase(key);
// leaveMutex();

返回;
}
virtual void clear(){
// enterMutex();
mHashtable.erase(mHashtable.begin(),mHashtable.end());
// leaveMutex();
}
虚拟bool isEmpty(){
bool ret;
// enterMutex();
ret = mHashtable.empty( );
// leaveMutex();
返回ret;
}

虚拟向量< pair< string,T> > toVector()
throw(NoSuchElementException)
{
vector< pair< string,T> > v;
// enterMutex();

if(mHashtable.empty()){
// leaveMutex();
抛出NoSuchElementException(string("哈希表是空的));
}
for(hash_map< string,T,hash< string>> :: iterator iter


需要使用typename - 就像这样:


for(typename hash_map< string,T,hash< string>> :: iterator iter

= mHashtable。 begin(); iter!= mHashtable.end(); ++ iter)
{
对< string,T> p(* iter); //(iter-> first,iter- >第二个);
v.insert(v.begin(),p);
}
// leaveMutex();
返回v;
}

受保护:
hash_map< string,T,hash< string>> mHashtable;
};

int
main(无效)
{
Hashtable< int> h;

返回0;
}
#ifdef NAMESPACES
}; // foobar
#endif

/ ** EMACS **
*局部变量:
*模式:c ++
* c-basic-offset: 4
*结束:
* /



在文章< bu ******* @ dispatch.concentric中。 net>,Gianni Mariani写道:

Luc Mazardo写道:


#include< pair.h> ;


^^^^^^^^不需要这个头 - std :: pair在std :: map中找到并且
pair.h是非标准的




对于想要使用对并且不需要地图/多图的人,

< utility>头。这个标题只定义了std :: pair和std :: relops


干杯,

-

Donovan Rebbechi http://pegasus.rutgers.edu/~elflord/


The following code works with g++ 2.75 but
i''ve some troubles with compiling with g++ 3.0.

Thanks in advance if you have a solution.

Here is the error message.

main.hpp:28: specializing `struct std::hash<std::string>'' in different
namespace
/usr/include/g++-v3/ext/stl_hash_fun.h:68: from definition of `template<class
_Key> struct std::hash''
make: *** [resource_identifier.lo] Error 1
#include <pair.h>
#include <string>
#include <map>
#include <vector>
#ifdef __GNUC__ /* grabbed in libstdc++ faq */
#if __GNUC__ < 3
#include <hash_map.h>
namespace Sgi { using ::hash_map; }; // inherit globals
#else
#include <ext/hash_map>
#if __GNUC_MINOR__ == 0
namespace Sgi = std; // GCC 3.0
#else
namespace Sgi = ::__gnu_cxx; // GCC 3.1 and later
#endif
#endif
#else // ... there are other compilers, right?
namespace Sgi = std;
#endif
using namespace std;
//TODO: include this definition in the Hashtable class
template<> struct hash<string>
{
size_t operator()(const string& s) const
{
return hash<char const*>()(s.c_str());
}
};
#ifdef NAMESPACES
namespace foobar {
#endif

class NoSuchElementException
{
public:
NoSuchElementException(string w) {_what = w;}
virtual ~NoSuchElementException() {}
virtual string what() { return _what; }
private:
string _what;
};
template <class T> class Hashtable //: public ost::Conditional
{
public:
Hashtable() {} //: Conditional() {}

virtual ~Hashtable() {clear(); }
virtual T put(const string& key, T value)
{
assert(key.c_str() != NULL); //TODO: must throw ?

// enterMutex();
T returnValue = mHashtable[key];
mHashtable[key] = value;
// leaveMutex();

return returnValue;
}

virtual T get(const string& key) throw (NoSuchElementException)
{
assert(key.c_str() != NULL); //TODO: must throw ?
// enterMutex();

if (mHashtable.empty())
{
// leaveMutex ();
throw NoSuchElementException (key);
}

if (mHashtable.find(key) == mHashtable.end())
{
// leaveMutex();
throw NoSuchElementException(key);
}

T returnValue = mHashtable[key];
//leaveMutex();

return returnValue;
}
virtual void del(const string& key) throw (NoSuchElementException)
{
assert(key.c_str() != NULL); //TODO: must throw ?
// enterMutex();

if (mHashtable.find(key) == mHashtable.end()) {
// leaveMutex();
throw NoSuchElementException(key);
}
mHashtable.erase (key);
// leaveMutex();

return;
}
virtual void clear() {
// enterMutex();
mHashtable.erase(mHashtable.begin(), mHashtable.end());
// leaveMutex();
}

virtual bool isEmpty () {
bool ret;
// enterMutex();
ret = mHashtable.empty ();
// leaveMutex();
return ret;
}

virtual vector<pair<string,T> > toVector()
throw (NoSuchElementException)
{
vector <pair<string, T> > v;
// enterMutex();

if (mHashtable.empty()) {
// leaveMutex();
throw NoSuchElementException(string("hashtable is empty"));
}

for(hash_map<string, T , hash<string> >::iterator iter
= mHashtable.begin(); iter != mHashtable.end(); ++iter)
{
pair <string, T> p(*iter);// (iter->first, iter->second);
v.insert(v.begin(), p);
}

//leaveMutex();
return v;
}

protected:
hash_map<string, T, hash<string> > mHashtable;
};

int
main(void)
{
Hashtable<int> h;

return 0;
}
#ifdef NAMESPACES
}; // foobar
#endif

/** EMACS **
* Local variables:
* mode: c++
* c-basic-offset: 4
* End:
*/

Here is my release of g++ 3.0:
$ g++-3.0 -v
Reading specs from /usr/lib/gcc-lib/i386-linux/3.0.4/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,proto,objc
--prefix=/usr --infodir=/share/info --mandir=/share/mx
Thread model: posix
gcc version 3.0.4

Here is my release of g++ 2.95:
g++ -v
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
gcc version 2.95.4 20011002 (Debian prerelease)

--
Lu*********@cvf.fr

解决方案

g++-3.0 -v
Reading specs from /usr/lib/gcc-lib/i386-linux/3.0.4/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,proto,objc
--prefix=/usr --infodir=/share/info --mandir=/share/mx
Thread model: posix
gcc version 3.0.4

Here is my release of g++ 2.95:
g++ -v
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
gcc version 2.95.4 20011002 (Debian prerelease)

--
Lu*********@cvf.fr


Luc Mazardo wrote:

The following code works with g++ 2.75 but
i''ve some troubles with compiling with g++ 3.0.

Thanks in advance if you have a solution.

Here is the error message.

main.hpp:28: specializing `struct std::hash<std::string>'' in different
namespace
/usr/include/g++-v3/ext/stl_hash_fun.h:68: from definition of `template<class
_Key> struct std::hash''
make: *** [resource_identifier.lo] Error 1
hash_map is not part of STL and so the gcc team ( in an effort to be
standards compliant) moved the hash* templates into the __gnu_cxx
namespace. The gcc 3.x series is also more standards compliant and so
you''ll need to fix some gcc 2.9x things.


#include <pair.h> ^^^^^^^^ don''t need this header - std::pair is found in std::map and
pair.h is non-standard #include <string>
#include <map>
#include <vector>
#ifdef __GNUC__ /* grabbed in libstdc++ faq */
#if __GNUC__ < 3
#include <hash_map.h>
namespace Sgi { using ::hash_map; }; // inherit globals
#else
#include <ext/hash_map>
#if __GNUC_MINOR__ == 0
namespace Sgi = std; // GCC 3.0
#else
namespace Sgi = ::__gnu_cxx; // GCC 3.1 and later
#endif
#endif
#else // ... there are other compilers, right?
namespace Sgi = std;
#endif
using namespace std;
using namespace __gnu_cxx;


//TODO: include this definition in the Hashtable class namespace __gnu_cxx
{
template<> struct hash<string>
{
size_t operator()(const string& s) const
{
return hash<char const*>()(s.c_str());
}
};
};


#ifdef NAMESPACES
namespace foobar {
#endif

class NoSuchElementException
{
public:
NoSuchElementException(string w) {_what = w;}
virtual ~NoSuchElementException() {}
virtual string what() { return _what; }
private:
string _what;
};
template <class T> class Hashtable //: public ost::Conditional
{
public:
Hashtable() {} //: Conditional() {}

virtual ~Hashtable() {clear(); }
virtual T put(const string& key, T value)
{
assert(key.c_str() != NULL); //TODO: must throw ?

// enterMutex();
T returnValue = mHashtable[key];
mHashtable[key] = value;
// leaveMutex();

return returnValue;
}

virtual T get(const string& key) throw (NoSuchElementException)
{
assert(key.c_str() != NULL); //TODO: must throw ?
// enterMutex();

if (mHashtable.empty())
{
// leaveMutex ();
throw NoSuchElementException (key);
}

if (mHashtable.find(key) == mHashtable.end())
{
// leaveMutex();
throw NoSuchElementException(key);
}

T returnValue = mHashtable[key];
//leaveMutex();

return returnValue;
}
virtual void del(const string& key) throw (NoSuchElementException)
{
assert(key.c_str() != NULL); //TODO: must throw ?
// enterMutex();

if (mHashtable.find(key) == mHashtable.end()) {
// leaveMutex();
throw NoSuchElementException(key);
}
mHashtable.erase (key);
// leaveMutex();

return;
}
virtual void clear() {
// enterMutex();
mHashtable.erase(mHashtable.begin(), mHashtable.end());
// leaveMutex();
}

virtual bool isEmpty () {
bool ret;
// enterMutex();
ret = mHashtable.empty ();
// leaveMutex();
return ret;
}

virtual vector<pair<string,T> > toVector()
throw (NoSuchElementException)
{
vector <pair<string, T> > v;
// enterMutex();

if (mHashtable.empty()) {
// leaveMutex();
throw NoSuchElementException(string("hashtable is empty"));
}

for(hash_map<string, T , hash<string> >::iterator iter
Need to use typename - like this:

for(typename hash_map<string, T , hash<string> >::iterator iter
= mHashtable.begin(); iter != mHashtable.end(); ++iter)
{
pair <string, T> p(*iter);// (iter->first, iter->second);
v.insert(v.begin(), p);
}

//leaveMutex();
return v;
}

protected:
hash_map<string, T, hash<string> > mHashtable;
};

int
main(void)
{
Hashtable<int> h;

return 0;
}
#ifdef NAMESPACES
}; // foobar
#endif

/** EMACS **
* Local variables:
* mode: c++
* c-basic-offset: 4
* End:
*/



In article <bu*******@dispatch.concentric.net>, Gianni Mariani wrote:

Luc Mazardo wrote:


#include <pair.h>


^^^^^^^^ don''t need this header - std::pair is found in std::map and
pair.h is non-standard



For someone who wants to use pair and doesn''t need map/multimap, the
<utility> header. This header just defines std::pair and std::relops

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/


这篇关于用g ++ 3.0编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆