g ++编译错误 [英] g++ compile error

查看:157
本文介绍了g ++编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Ubuntu的新手。
我试图编译一个简单的Hello World! Ubuntu 11.04中的c ++代码(在终端中):

  gcc -Wall -W -Werror tex.cpp -o tex。但是编译器返回了很多错误:


/tmp/ccL8c1p8.o:在函数main中:
tex.cpp :(。text + 0xa):未定义引用`std :: cout'
tex.cpp :(。text + 0xf):未定义引用`std :: basic_ostream< char,std :: char_traits< char> >& std :: operator<< < std :: char_traits< char> >(std :: basic_ostream< char,std :: char_traits< char>& char,char const *)'
/tmp/ccL8c1p8.o:在函数`__static_initialization_and_destruction_0(int,int) b $ b tex.cpp :(。text + 0x3d):未定义引用`std :: ios_base :: Init :: Init()'
tex.cpp :(。text + 0x42):未定义引用` std :: ios_base :: Init ::〜Init()'
collect2:ld返回1退出状态
mohrd @ mio:〜$ gcc -Wall -W -Werror tex.cpp -o tex。
/tmp/ccEke5JP.o:在函数`main'中:
tex.cpp :( .text + 0xa):未定义引用`std :: cout'
tex.cpp .text + 0xf):未定义引用`std :: basic_ostream< char,std :: char_traits< char> >& std :: operator<< < std :: char_traits< char> >(std :: basic_ostream< char,std :: char_traits< char>& char,char const *)'
/tmp/ccEke5JP.o:在函数`__static_initialization_and_destruction_0(int,int) b $ b tex.cpp :(。text + 0x3d):未定义引用`std :: ios_base :: Init :: Init()'
tex.cpp :(。text + 0x42):未定义引用` std :: ios_base :: Init ::〜Init()'
collect2:ld返回1退出状态


$ b b

简单代码:

  #include< algorithm> 
#include< iostream>
using namespace std;

int main()
{
std :: cout< 你好,世界!;
return 0;
}

为什么?我应该怎么办?



很多谢谢...

解决方案

您需要使用g ++(或c ++)命令来编译您的程序,使用gcc将编译为c ++,因为.cpp扩展而不是链接在所需的c ++库中。


I'm a newbie in Ubuntu. I tried to compile a simple "Hello World!" c++ code in Ubuntu 11.04, with that code (in terminal):

gcc -Wall -W -Werror tex.cpp -o tex. 

but compiler returned a lot of errors :

/tmp/ccL8c1p8.o: In function `main':
tex.cpp:(.text+0xa): undefined reference to `std::cout'
tex.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccL8c1p8.o: In function `__static_initialization_and_destruction_0(int, int)':
tex.cpp:(.text+0x3d): undefined reference to `std::ios_base::Init::Init()'
tex.cpp:(.text+0x42): undefined reference to `std::ios_base::Init::~Init()'
collect2: ld returned 1 exit status
mohrd@mio:~$ gcc -Wall -W -Werror tex.cpp -o tex.
/tmp/ccEke5JP.o: In function `main':
tex.cpp:(.text+0xa): undefined reference to `std::cout'
tex.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccEke5JP.o: In function `__static_initialization_and_destruction_0(int, int)':
tex.cpp:(.text+0x3d): undefined reference to `std::ios_base::Init::Init()'
tex.cpp:(.text+0x42): undefined reference to `std::ios_base::Init::~Init()'
collect2: ld returned 1 exit status

simple code :

#include <algorithm>
#include <iostream>
using namespace std;

int main ()
{
  std::cout << "Hello World!";
  return 0;
}

Why? and what should I do???

many thanks ...

解决方案

You need to use the g++ (or c++) command to compile your program, using "gcc" will compile it as c++ due to the .cpp extension but not link in the required c++ libraries.

这篇关于g ++编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆