在Ubuntu下,使用GCC编译器生成可执行文件的过程分为以下几个步骤:
sudo apt update
sudo apt install build-essential
hello.c
的C程序文件:#include<stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
/home/username/Documents
目录中,可以使用以下命令进入该目录:cd /home/username/Documents
gcc hello.c -o hello
这将生成一个名为hello
的可执行文件。对于C++文件,使用以下命令:
g++ hello.cpp -o hello
这将生成一个名为hello
的可执行文件。
chmod +x hello
./hello
这将运行hello
程序,你将看到输出"Hello, World!"。
以上就是在Ubuntu下使用GCC编译器生成可执行文件的过程。如果遇到任何问题,请查阅相关文档或寻求社区支持。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:ubuntu gcc如何生成可执行文件