LinuxSir.cn,穿越时空的Linuxsir!

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

郁闷的c++程序题

[复制链接]
发表于 2005-7-10 09:27:55 | 显示全部楼层 |阅读模式
程序内容
/////////////////////////////////////////////
//        Name: hello                      //
//      Author: libertine                  //
//        Data: 2005/07/10                 //
/////////////////////////////////////////////

#include "iostream"
using namespace std;
int main()
{
        cout<<"hello world"<<endl;
        return 0;
}
~
gcc hello.cpp
然后是出错信息
/tmp/ccKD7fzw.o(.text+0x25): In function `main':
hello.cpp: undefined reference to `std::cout'
/tmp/ccKD7fzw.o(.text+0x2a):hello.cpp: 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/ccKD7fzw.o(.text+0x35):hello.cpp: 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/ccKD7fzw.o(.text+0x3b):hello.cpp: undefined reference to `std::basic_ostream<char, std::char_traits<char> >:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccKD7fzw.o(.text+0x59): In function `__tcf_0':
hello.cpp: undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccKD7fzw.o(.text+0x86): In function `__static_initialization_and_destruction_0(int, int)':
hello.cpp: undefined reference to `std::ios_base::Init::Init()'
/tmp/ccKD7fzw.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld 返回 1

然后实验了 g++ -o hello hello.cpp
成功
发现原来c++要用g++指明,不能用gcc来个模糊的编译呀
以前在win下真是不知道呢
呵呵
学习了东西,爽。
发表于 2005-7-10 10:38:13 | 显示全部楼层
你的认识是不对的。具体的可以搜索一下论坛。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-7-10 11:27:10 | 显示全部楼层
好的,我去看看
谢谢了
回复 支持 反对

使用道具 举报

发表于 2005-7-10 11:34:25 | 显示全部楼层
可以明白的说下吗?不明白你们说的是什么啊!哈哈
回复 支持 反对

使用道具 举报

发表于 2005-7-11 03:38:53 | 显示全部楼层
用gcc编译你得自己加上-lstdc++
回复 支持 反对

使用道具 举报

发表于 2005-7-12 16:54:06 | 显示全部楼层
Post by x11
用gcc编译你得自己加上-lstdc++


我最近开始使用gcc,遇到跟楼主一样的问题,正到处找答案呢。
加了-lstdc++参数后通过了编译,谢谢楼上的。
回复 支持 反对

使用道具 举报

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

本版积分规则

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