1. 確認Linux系統(tǒng)是否已經(jīng)安裝了GCC
Linux系統(tǒng)中一般都會自帶GCC,查看方式如下所示:
gcc -v
- 例子
[necde@fedora c_workspace]$ gcc -v
使用內(nèi)建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/12/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
目標:x86_64-redhat-linux
配置為:../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-12.2.1-20220819/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none --without-cuda-driver --enable-offload-defaulted --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1
線程模型:posix
Supported LTO compression algorithms: zlib zstd
gcc 版本 12.2.1 20220819 (Red Hat 12.2.1-2) (GCC)
如果沒有安裝池充,可以搜索自行安裝桩引,很簡單的坑匠,不管是百度還是必應還是谷歌卧惜,一定都可以很快搜索到安裝的指令。
2. 編寫程序
這里以一個簡單的hello.c
程序來演示咽瓷,至于編輯器的使用,這里直接使用vi/vim
#include <stdio.h>
int main() {
printf("Hello, world \n");
return 0;
}
3. 編譯
直接編譯
gcc hello.c
此時該目錄下會出現(xiàn)一個a.out
若是多個c文件一起編譯闪朱,則可以用以下的例子:
gcc test1.c test2.c -o test.out
其中-o
可以指定輸出的文件名稱奋姿,上邊的指令會輸出一個 test.out
素标,注意輸出的文件名可以不一定以.out
結(jié)尾,但是還是建議以 .out
結(jié)尾
4. 執(zhí)行
./a.out
例子:
[necde@fedora c_workspace]$ ./a.out
Hello, World
如果覺得有收獲就點個贊吧,更多知識退腥,請點擊關(guān)注查看我的主頁信息哦~