在ubuntu下编译最简单的c语言程序

今天边看书,边打算尝试一下,在ubuntu下写个最小的程序试试。建立一个hello.c的文件。

1 #include <stdio.h>
2 int main(void)
3 {
4 printf("hello!\n");
5 printf("hello world from process id is %d\n",getpid());
6 return 0;
7 }

但是在终端用gcc 编译,去说没有头文件,之后才发现是因为没有装c的标准库的原因。

安装 g++,  sudo apt-get install g++

Ubuntu就安裝g++后,stdio.h就在/usr/include/下了,可以自己查询。

然后这时候,我们再次执行,结果如下L

candycai@candycai-ubuntu:~$ gcc hello.c -o hello
candycai@candycai-ubuntu:~$ ./hello
hello!
hello world from process id is 10087


(我也是菜鸟,只是记录一些我的鸟爪,以便后续学习用)

原文地址:https://www.cnblogs.com/candycaicai/p/1968216.html