论坛: 编程破解 标题: gcc编译c++的问题 复制本贴地址    
作者: kert_t8 [kert_t8]    论坛用户   登录
代码:

#include <iostream>
int main() {
        int a,b;
        a=0;
        b=1;
        cout<<a<<b<<endl;
        return 0;
}



这么一行代码都通不过
引用:

template.cpp: In function `int main()':
template.cpp:13: error: `cout' undeclared (first use this function)
template.cpp:13: error: (Each undeclared identifier is reported only once for
  each function it appears in.)
template.cpp:13: error: `endl' undeclared (first use this function)





地主 发表时间: 05-09-08 20:00

回复: jhkdiy [jhkdiy]   版主   登录
#include <iostream> 这个不需要转换为:
#include <iostream.h> 吗?

B1层 发表时间: 05-09-08 23:26

回复: kert_t8 [kert_t8]   论坛用户   登录
我听说不需要

而且我换成iostream.h以后好像错误更多

B2层 发表时间: 05-09-09 20:03

回复: kert_t8 [kert_t8]   论坛用户   登录
加上using namespace std;后出现

引用:
[raody@ServerLinux cpractice]$ gcc template.cpp
/tmp/ccbFTZkU.o(.text+0x22): 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/ccbFTZkU.o(.text+0x33): In function `main':
: undefined reference to `std::cout'
/tmp/ccbFTZkU.o(.text+0x38): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
/tmp/ccbFTZkU.o(.text+0x41): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
/tmp/ccbFTZkU.o(.text+0x4a): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccbFTZkU.o(.text+0x76): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccbFTZkU.o(.text+0xa5): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccbFTZkU.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
[raody@ServerLinux cpractice]$



B3层 发表时间: 05-09-09 20:28

回复: kert_t8 [kert_t8]   论坛用户   登录
gcc只能编译c++文件不能连接,所以gcc -c template.cpp -o template.o没有问题
但是gcc template.o就出错了

解决的办法是g++ template.cpp

哎,我要倒了

B4层 发表时间: 05-09-09 20:50

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号