本文介绍了为什么我不能在C ++中编译HelloWorld?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在C ++中编译一个简单的Hello World程序,但我一直收到以下错误...为什么?
I'm trying to compile a simple Hello World program in C++ but I keep getting the following error...why?
gcc -o HelloWorldCompiled HelloWorld.cc
/tmp/ccvLW1ei.o: In function `main':
HelloWorld.cc:(.text+0xa): undefined reference to `std::cout'
HelloWorld.cc:(.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/ccvLW1ei.o: In function `__static_initialization_and_destruction_0(int, int)':
HelloWorld.cc:(.text+0x3d): undefined reference to `std::ios_base::Init::Init()'
HelloWorld.cc:(.text+0x42): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccvLW1ei.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
这是我的程序:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World\n";
}
推荐答案
使用 g ++
不 gcc
。
g++ -o hwcompiled helloworld.cc
这篇关于为什么我不能在C ++中编译HelloWorld?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!