日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2024/2/28 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用gcc编译c语言程序,用GCC编译C ++程序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在這里,我們將看到如何使用GCC(GNU C編譯器)編譯C ++程序。讓我們考慮一下,我們要編譯這個程序。

示例#include

using?namespace?std;

main()?{

cout?<

}

如果這是一個C程序,我們可以像下面這樣用GCC進行編譯-gcc?test.c

但是,如果我們將c ++文件名放在該區域中,則可能會產生一些錯誤。gcc?test.cpp

輸出結果/tmp/ccf1KGDi.o:?In?function?`main':

1325.test.cpp:(.text+0xe):?undefined?reference?to?`std::cout'

1325.test.cpp:(.text+0x13):?undefined?reference?to?`std::basic_ostream?>&

std::operator<?>(std::basic_ostream?>&,?char?const*)'

1325.test.cpp:(.text+0x1d):?undefined?reference?to?`std::basic_ostream?>&?std::endl

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

1325.test.cpp:(.text+0x28):?undefined?reference?to?`std::ostream::operator<

/tmp/ccf1KGDi.o:?In?function?`__static_initialization_and_destruction_0(int,?int)':

1325.test.cpp:(.text+0x58):?undefined?reference?to?`std::ios_base::Init::Init()'

1325.test.cpp:(.text+0x6d):?undefined?reference?to?`std::ios_base::Init::~Init()'

collect2:?error:?ld?returned?1?exit?status

$

這不是編譯錯誤。這是鏈接錯誤。要添加正確的鏈接器,我們必須使用–lstdc ++選項。gcc?test.cpp?-lstdc++

輸出結果$?./a.out

Hello?World.?This?is?C++?program

$

總結

以上是生活随笔為你收集整理的使用gcc编译c语言程序,用GCC编译C ++程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。