LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 796|回复: 7

suse 9.2下只能编译C语言,没 法编译C++

[复制链接]
发表于 2005-4-16 15:25:44 | 显示全部楼层 |阅读模式
我以前用的RH 9也出现这样的情况,只能是编译C程序,不能编译C++
出现如下错误,请各位高手帮忙解决啊
错误如下:
In file included from /usr/include/g++/backward/iostream.h:31,
                 from a.C:1:
/usr/include/g++/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using oneof 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.
a.C:3: error: `main' must return `int'
发表于 2005-4-16 17:17:39 | 显示全部楼层
这个问题是因为你使用了stl中已经被c++标准放弃的类头文件<strstream.h>,你的第二个错误是g++要求main函数必须返回int类型,这也是c++标准委员会定义的两种main声明之一,并不是不能作c++程序
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-4-16 17:41:18 | 显示全部楼层
这跟windows下的C++程序不一样?
windows下的C++并没有这些规定啊,
比如
main(void)
{
printf("kdjf");
}
这段C程序要用C++输出的话,应该怎么写
还有
linux下的C++是不是跟windows下的有很多的不一样呢
回复 支持 反对

使用道具 举报

发表于 2005-4-17 01:03:54 | 显示全部楼层
现在的VC.NET 2003也是采用标准C++了,小弟不才,测了一下STL,BOOST等库的使用,还是很不错的。

大家应该“以时俱进才行啊".


楼主这样的情型,要么就找一个旧版GNU开发工具链的装上,修改g++联接试试。。
回复 支持 反对

使用道具 举报

发表于 2005-4-17 16:51:49 | 显示全部楼层
vc采用的并不是完全标准的c++,所以你可以使用void main()这样的声明
回复 支持 反对

使用道具 举报

发表于 2005-4-17 17:45:25 | 显示全部楼层
g++, 加上s参数就可以了.
回复 支持 反对

使用道具 举报

发表于 2005-4-17 17:49:41 | 显示全部楼层
这是我在redhat el as 4下编译的,
写一个入门的c++程序,hello.cpp
#include<iostream>
using namespace std;
int main ()
{
   cout<<"hello,linux"<<endl;
}
g++ -s -o hello hello.cpp
./hello
看看行不?好像是这样吧?我现在在win下,没办法试验.
回复 支持 反对

使用道具 举报

发表于 2005-4-17 21:40:35 | 显示全部楼层
在函数结束时要有return 0;
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表