微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

g ++编译错误

我是Ubuntu的新手。 我试图编译一个简单的“Hello World!” Ubuntu 11.04中的代码(在terminal中):

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

但编译器返回了很多错误

/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,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

简单的代码

#include <algorithm> #include <iostream> using namespace std; int main () { std::cout << "Hello World!"; return 0; }

为什么? 我该怎么办?

如何与VBO绘制三angular形?

在Windows中运行Eclipse C ++中的Hello World应用程序

Wine是否可以使用Simulink Real-Time C API?

升压语言环境的string转换:在Windows和Linux上的不同行为

如何检索剪贴板文件指针CF_HDROP

非常感谢 …

跳过Aero窗口animation

“控制台”,“cmd.exe”,“shell”之间的区别?

在C中使用数据包模式时,如何绑定到认接口?

是否有strsep()的窗口变体

连接到没有用户名/密码的远程机器

你需要使用g ++(或者c ++)命令来编译你的程序,使用“gcc”会将它编译为c ++,这是由于.cpp扩展名,而不是链接在所需的c ++库中。

使用g ++而不是gcc来编译C ++代码

g++ -Wall -W -Werror tex.cpp -o tex

认情况下,gcc不链接stdc ++库,这是您的代码所必需的。

使用g++命令而不是gcc 。

尝试:

g++ -Wall hello.cpp -o hello

因为你正试图编译C++代码,而不是C代码

-Wall表示Warning ALL ,所以你已经看到了所有的警告

此外,有意义地命名您的程序和源文件

LE:当然 – -Werror仍然是你的选择

LE2:在你的代码中不需要#include <algorithm> ,所以你可以删除它!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐