LinuxSir.cn,穿越时空的Linuxsir!

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

问一下,GCC编译的这个问题?

[复制链接]
发表于 2003-11-13 16:56:01 | 显示全部楼层 |阅读模式
我的系统是fedora,我用gedit编了一个c++源文件,保存为hhh.cxx,但我在终端下用gcc编译不出可执行文件呀?
    这是我编的:
#include <iostream.h>
   main()
     {
         cout<<"hello!"<<endl;
     }
------------------------------------------------------------------------   
   [jinke@fedora jinke]$ gcc -o wo hhh.cxx
In file included from /usr/include/c++/3.3.2/backward/iostream.h:31,
                 from hhh.cxx:1:
/usr/include/c++/3.3.2/backward/backward_warning.h:32:2: warning: #warning This
file includes at least one deprecated or antiquated header. Please consider usin
g 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 <s
stream> instead of the deprecated header <strstream.h>. To disable this warning
use -Wno-deprecated.
/tmp/ccDGqQIh.o(.text+0x14): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std                                                              ::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<                                                              char> >&)'
/tmp/ccDGqQIh.o(.text+0x21): In function `main':
: undefined reference to `std::cout'
/tmp/ccDGqQIh.o(.text+0x26): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std                                                              :perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits                                                              <char> >&, char const*)'
/tmp/ccDGqQIh.o(.text+0x2f): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >:pe                                                              rator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostrea                                                              m<char, std::char_traits<char> >&))'
/tmp/ccDGqQIh.o(.text+0x5c): In function `__static_initialization_and_destructio                                                              n_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccDGqQIh.o(.text+0x8b): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccDGqQIh.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
发表于 2003-11-13 20:29:35 | 显示全部楼层
g++ -o wo hhh.cxx
发表于 2003-11-13 20:46:30 | 显示全部楼层

  1. #include <iostream>       //不是iostream.h
  2. using namespace std;      //要加上这一行

  3. main()......              //其余不变
复制代码
 楼主| 发表于 2003-11-13 21:23:52 | 显示全部楼层
怎么搞的?和C++不一样了呀,C++用的就是<iostream.h>,还有:
using namespace std????这不和windows下的visual studio.net2003一样了吗?
发表于 2003-11-14 04:02:09 | 显示全部楼层
C++也是在逐步发展的,楼上给出的是老代码,VS2003则是根据新标准而涉及,但MS的一贯风格VC.NET 7.1(VS.NET 2003)只能保证9成7的兼容性.呵呵97%是真的,看微软产品新闻自个说的.

VC.NET 2003只支持新风格(C++98标准,C++第一个国际ISO标准),如果要用VC.NET 2003编写老样的程序则需要第三方STL(我用STLPort!)模板支援以获取相关头文件
 楼主| 发表于 2003-11-14 12:53:59 | 显示全部楼层
我学C++时是根据"钱能"老师的一本书上学的,上面说的都是iostream.h,而且也不用加上using namespace std,   我应如何适应这种新的C++标准呢,在哪里可以获得这方面的知识?
   请知道的朋友指点我一条学习的道路,谢谢!
发表于 2003-11-16 11:54:14 | 显示全部楼层
<iostream>是标准C++上用的所有名字都在名字空间std中!
则<iostream.h>是非标准之前的并没有加入到名字空间中,一些编译器这样用.如VC.
LINUX上的G++是符合标准的(不是完全)所以要用名字空间版本的<iostream>.
去看看effective c++ (最后两条)
还有:
main()
必须是int main()
它必须返回int, 而内部可以没有return语句,因为它默认返回0.
而main()形参可以不要,与为void一样!
建议去看看Bjarne的FAQ.
 楼主| 发表于 2003-11-17 12:26:34 | 显示全部楼层
谢谢大家的帮助!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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