300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 使用gcc编译c语言程序 用GCC编译C ++程序

使用gcc编译c语言程序 用GCC编译C ++程序

时间:2019-08-24 21:22:59

相关推荐

使用gcc编译c语言程序 用GCC编译C ++程序

在这里,我们将看到如何使用GCC(GNU C编译器)编译C ++程序。让我们考虑一下,我们要编译这个程序。

示例#include

usingnamespacestd;

main(){

cout<

}

如果这是一个C程序,我们可以像下面这样用GCC进行编译-gcctest.c

但是,如果我们将c ++文件名放在该区域中,则可能会产生一些错误。gcctest.cpp

输出结果/tmp/ccf1KGDi.o:Infunction`main':

1325.test.cpp:(.text+0xe):undefinedreferenceto`std::cout'

1325.test.cpp:(.text+0x13):undefinedreferenceto`std::basic_ostream>&

std::operator<>(std::basic_ostream>&,charconst*)'

1325.test.cpp:(.text+0x1d):undefinedreferenceto`std::basic_ostream>&std::endl

std::char_traits>(std::basic_ostream>&)'

1325.test.cpp:(.text+0x28):undefinedreferenceto`std::ostream::operator<

/tmp/ccf1KGDi.o:Infunction`__static_initialization_and_destruction_0(int,int)':

1325.test.cpp:(.text+0x58):undefinedreferenceto`std::ios_base::Init::Init()'

1325.test.cpp:(.text+0x6d):undefinedreferenceto`std::ios_base::Init::~Init()'

collect2:error:ldreturned1exitstatus

$

这不是编译错误。这是链接错误。要添加正确的链接器,我们必须使用–lstdc ++选项。gcctest.cpp-lstdc++

输出结果$./a.out

HelloWorld.ThisisC++program

$

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。