LinuxSir.cn,穿越时空的Linuxsir!

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

关于gcc

[复制链接]
发表于 2006-9-17 22:18:08 | 显示全部楼层 |阅读模式
昨天装了Ubuntu,今天装了gcc,但这么都找不到头文件stdio.h之类的,找到解决方法,是要安装libc6-dev,不知道还有什么要安装的?
C++仍然不能支持,比如找不到iostream.h。。应该怎么办?
发表于 2006-9-17 22:26:54 | 显示全部楼层
Post by huyongzs

默认安装的Ubuntu没有安装Gcc和其他的开发辅助工具,但是用apt-get可以轻松的安装这些软件

sudo apt-get install manpages-dev
安装C语言函数的Man文件

sudo apt-get install build-essential
完成gcc,g++,make的安装

sudo apt-get install libc6-dev libstdc++6-4.0-dev
Include&lib

sudo apt-get install autoconf automake1.9
安装autoconf automake1.9

sudo apt-get install binutils-doc cpp-doc gcc-4.0-doc gcc-doc glibc-doc libstdc++6-4.0-doc stl-manual cpp-4.0-doc
安装文档

sudo apt-get install flex bison
安装flex和bison


你试试看吧
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-18 00:19:58 | 显示全部楼层
thx...我明天试试
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-18 11:23:18 | 显示全部楼层
编译C++程序时还是不行。找不到<iostream.h>
另外推荐安装的软件包:
debian-keyring gcc-4.0-doc lib64stdc++6 libtool
gcc-doc glibc-doc libstdc++6-4.0-doc
autoconf2.13 autobook autoconf-archive gnu-standards
bison-doc
  libtool-doc g77 fortran77-compiler gcj
  libltdl3-dev
这是安装的时候apt-get建议的包,不知道
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-18 11:28:10 | 显示全部楼层
哦。。。。搞错了,C++程序 是用G++的吧,改了就行
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-18 11:39:31 | 显示全部楼层
还有一个奇怪的问题
如果程序源文件是.c文件的话,那gcc会报错
gcc hel.c -o hel
hel.c:1:22: error: iostream.h: No such file or directory
hel.c: 在函数 ‘main’ 中:
hel.c:4: 错误: ‘cout’ 未声明 (在此函数内第一次使用)
hel.c:4: 错误: (即使在一个函数内多次出现,每个未声明的标识符在其
hel.c:4: 错误: 所在的函数内只报告一次。)
如果我把文件名改成.cpp文件之后,gcc输出
gcc hel.cpp -o hel
In file included from /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/backward/iostream.h:31,
                 from hel.cpp:1:
/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/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 <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
/tmp/cct44fVH.o: In function `main':hel.cpp.text+0x27):对‘std::cout’未定义的 引用
:hel.cpp.text+0x2c):对‘std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)’未定义的引用
:hel.cpp.text+0x3c):对‘std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)’未定义的引用
/tmp/cct44fVH.o: In function `__tcf_0':hel.cpp.text+0x56):对‘std::ios_base::Init::~Init()’未定义的引用
/tmp/cct44fVH.o: In function `__static_initialization_and_destruction_0(int, int)':hel.cpp.text+0x7f):对‘std::ios_base::Init::Init()’未定义的引用
/tmp/cct44fVH.o.eh_frame+0x11):对‘__gxx_personality_v0’未定义的引用
collect2: ld 返回 1

如果用g++的话
g++ hel.cpp -o hel
In file included from /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/backward/iostream.h:31,
                 from hel.cpp:1:
/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/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 <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
从这个看来,gcc跟g++的输出最前面的一段是相同的。gcc应该是可以根据文件名的扩展名部分来识别源文件的,但为什么用G++可以编译成功,用gcc就不行呢?

另外,如果按照提示用<iostream>代替<iostream.h>结果连g++都出错,除了用-Wno-deprecated之外,有什么其他办法?
回复 支持 反对

使用道具 举报

发表于 2006-9-18 11:51:16 | 显示全部楼层
*.h 的頭文件都是老式的,新標准統一使用不帶 .h 的頭文件。

用gcc當然也可以編譯,不過要指定c++標准庫。
  1. gcc test.cpp -lstdc++ -o test
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-18 15:55:59 | 显示全部楼层
哦。。原来这样。
谢谢
回复 支持 反对

使用道具 举报

发表于 2006-9-19 22:45:07 | 显示全部楼层
那得用标准库了,现在基本上已经不用.h文件了
回复 支持 反对

使用道具 举报

发表于 2006-9-27 09:50:07 | 显示全部楼层
sgxiao@sgxiao-desktop:~$ sudo apt-get install build-essential
Reading package lists... Done
Building dependency tree... Done
Package build-essential is not available, but is referred to by another package.This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package build-essential has no installation candidate





please tell me why my situation above.......
回复 支持 反对

使用道具 举报

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

本版积分规则

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