linux下如何使用SGI STL?

hz129 2003-12-30 02:32:50
我在linux9(G++3.2.2)下,默认使用的标准STL库,我想使用SGI STL库,请问该如何设置?
...全文
330 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hz129 2003-12-31
  • 打赏
  • 举报
回复
终于搞定了,原来G++3.2.2使用的还是SGI STL,但是它把非标准的部分放在了ext子目录下,只要改为:

#include <ext/slist>
#include <iostream>
#include <algorithm>
using namespace std;
using namespace __gnu_cxx;

就行了。
sevencat 2003-12-31
  • 打赏
  • 举报
回复
??不是说GCC用的就是SGI的STL吗?
hz129 2003-12-31
  • 打赏
  • 举报
回复
我看了一下slist的代码,其中有如下一行:
...
__STL_BEGIN_NAMESPACE
...

在stl_config.h中有此宏的定义:
# define __STL_BEGIN_NAMESPACE namespace std {
我的GCC版本>2.8,所以此宏是有效的

那么我还是应该使用std才对吧
victor_cui 2003-12-30
  • 打赏
  • 举报
回复
std
victor_cui 2003-12-30
  • 打赏
  • 举报
回复
你既然不使用stl库,为什么还是用它的名字空间啊,还有就是要需要声明使用SGI的名字空间
hz129 2003-12-30
  • 打赏
  • 举报
回复
源程序如下:
// file : 4slist-test.cpp
#include <slist>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
int i;
slist<int> islist;
cout << "size=" << islist.size() << endl; // size=0

islist.push_front(9);
islist.push_front(1);
islist.push_front(2);
islist.push_front(3);
islist.push_front(4);
cout << "size=" << islist.size() << endl; // size=5

slist<int>::iterator ite = islist.begin();
slist<int>::iterator ite2 = islist.end();
for(; ite != ite2; ++ite)
cout << *ite << ' ';
cout << endl; // 4 3 2 1 9

ite = find(islist.begin(), islist.end(), 1);
if (ite != 0)
islist.insert(ite, 99);

cout << "size=" << islist.size() << endl; // size=6
cout << *ite << endl; // 1

ite = islist.begin();
ite2 = islist.end();
for(; ite != ite2; ++ite)
cout << *ite << ' ';
cout << endl; // 4 3 2 99 1 9

ite = find(islist.begin(), islist.end(), 3);
if (ite != 0)
cout << *(islist.erase(ite)) << endl; // 2

ite = islist.begin();
ite2 = islist.end();
for(; ite != ite2; ++ite)
cout << *ite << ' ';
cout << endl; // 4 2 99 1 9
}

g++ -I/usr/include/g++-3 xxx.cpp -o xxx.out

错误信息如下:
In file included from /usr/include/c++/3.2.2/backward/new.h:33,
from /usr/include/g++-3/stl_algobase.h:52,
from /usr/include/g++-3/slist:18,
from 408slist-test.cpp:2:
/usr/include/c++/3.2.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
In file included from /usr/include/c++/3.2.2/backward/new.h:34,
from /usr/include/g++-3/stl_algobase.h:52,
from /usr/include/g++-3/slist:18,
from 408slist-test.cpp:2:
/usr/include/c++/3.2.2/new:79: `size_t' undeclared in namespace `std'
/usr/include/c++/3.2.2/new:79: declaration of `operator new' as non-function
/usr/include/c++/3.2.2/new:79: invalid declarator
/usr/include/c++/3.2.2/new:80: `size_t' undeclared in namespace `std'
/usr/include/c++/3.2.2/new:80: declaration of `operator new []' as non-function
/usr/include/c++/3.2.2/new:80: invalid declarator
/usr/include/c++/3.2.2/new:83: `size_t' undeclared in namespace `std'
/usr/include/c++/3.2.2/new:83: parse error before `::' token
/usr/include/c++/3.2.2/new:83: `operator new' takes type `size_t' (`unsigned
int') as first parameter
/usr/include/c++/3.2.2/new:84: `size_t' undeclared in namespace `std'
/usr/include/c++/3.2.2/new:84: parse error before `::' token
/usr/include/c++/3.2.2/new:84: `operator new' takes type `size_t' (`unsigned
int') as first parameter
/usr/include/c++/3.2.2/new:89: `size_t' undeclared in namespace `std'
/usr/include/c++/3.2.2/new:89: parse error before `*' token
/usr/include/c++/3.2.2/new:89: `operator new' takes type `size_t' (`unsigned
int') as first parameter
/usr/include/c++/3.2.2/new: In function `void* operator new(unsigned int,
...)':
/usr/include/c++/3.2.2/new:89: `__p' undeclared (first use this function)
/usr/include/c++/3.2.2/new:89: (Each undeclared identifier is reported only
once for each function it appears in.)
/usr/include/c++/3.2.2/new: At global scope:
/usr/include/c++/3.2.2/new:90: `size_t' undeclared in namespace `std'
/usr/include/c++/3.2.2/new:90: parse error before `*' token
/usr/include/c++/3.2.2/new:90: `operator new' takes type `size_t' (`unsigned
int') as first parameter
In file included from /usr/include/g++-3/slist:19,
from 408slist-test.cpp:2:
/usr/include/g++-3/stl_alloc.h:704: warning: `typename
__default_alloc_template<threads, inst>::_Obj' is implicitly a typename
/usr/include/g++-3/stl_alloc.h:704: warning: implicit typename is deprecated,
please see the documentation for details
victor_cui 2003-12-30
  • 打赏
  • 举报
回复
是编译期错误还是连接错误?
hz129 2003-12-30
  • 打赏
  • 举报
回复
标准STL头文件目录:/usr/include/c++/3.2.2
SGI STL头文件目录:/usr/include/g++-3
但我不知道lib的目录在哪里,我现在用
g++ -I/usr/include/g++-3 xxx.cpp -o xxx.out
出现了一堆的错误:(
victor_cui 2003-12-30
  • 打赏
  • 举报
回复
可以这样做,首先当然是要包含SGI的头文件,并引用其中的模板类,编译是在makefile中包含-I 相应头文件路径,当然如果你已经在包含的时候写了全路经可以声调这一选项。然后连接的时候指定库 -L (lib)即可,如果定义了库路径的环境,可以直接输入库文件名,如果没有的话需要制定全路经

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧