Ubuntu系统下配置C语言编译环境

配置gcc
对于一个全新的ubuntu系统,可能还没有配置c语言编译环境,这时候需要用户自己安装。
:~$ gcc -vcommand 'gcc' not found, but can be installed with:sudo apt install gcc查看版本gcc -v,确实没有c语言编译环境gcc
:~$ apt-get install gcc e: could not open lock file /var/lib/dpkg/lock-frontend - open (13: permission denied)e: unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?:~$ sudo apt-get install gcc [sudo] password for alice: reading package lists... donebuilding dependency tree... donereading state information... done用apt命令配置gcc环境apt-get install gcc ,首次尝试未能成功,因为没有管理员权限,加上sudo, sudo apt-get****install gcc 再次尝试,可以看到成功安装。
:~$ gcc -vusing built-in specs.collect_gcc=gcccollect_lto_wrapper=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapperoffload_target_names=nvptx-none:amdgcn-amdhsaoffload_target_default=1target: x86_64-linux-gnu至此,gcc环境配置成功。编写一个c语言程序测试
#include int main(){ printf(hello world!n); return 0;}测试文件test.c放在document下面,经过编译gcc test.c 、运行./a. out ,成功输出“hello world!”
:~/documents$ vi test.c:~/documents$ gcc test.c :~/documents$ lsa.out test.c:~/documents$ ./a.out hello world!配置makefile
makefile可以很好地管理c语言程序,makefile的配置与gcc类似。
:~$ make -vcommand 'make' not found, but can be installed with:sudo apt install make # version 4.3-4.1build1, orsudo apt install make-guile # version 4.3-4.1build1查看系统make -v,确实没有make环境,现在配置该环境sudo apt-get install make
:~$ sudo apt-get install make[sudo] password for alice: reading package lists... donebuilding dependency tree... donereading state information... donesuggested packages: make-docthe following new packages will be installed: make再次查看,make环境配置完成
:~$ make -vgnu make 4.3built for x86_64-pc-linux-gnucopyright (c) 1988-2020 free software foundation, inc.利用上述c语言程序,测试makefile,在makefile文件中,写入下面的代码(其中makefile首字母大写,没有后缀名)
test : test.o gcc -o test test.otest.o : test.c gcc -c -o test.o test.cclean : rm -f main test.o每一行命令的gcc前面,一定是tab键,不是空格,否则编译make报错。
:~/documents$ makegcc -c -o test.o test.cgcc -o test test.o:~/documents$ ./test hello world!:~/documents$ lsa.out makefile test test.c test.o经过编译make、运行./test ,仍然可以正确输出。

苹果iPhone第三季度营收可能会下滑,但iPhone12将推动未来增长
MagSafe平替无线充电器,iphone12无线充电器推荐
Uber无人车传感器7个减到1个,是技术调整还是激进做法
华为禁入日本市场是真的吗?
中勒索病毒后如何清除?爆发出现新变种,电脑中病毒了该如何应对?最有效措施在此!
Ubuntu系统下配置C语言编译环境
出货量千万台,异军突起的5G FWA市场!
可再生能源配额制在解决弃风弃光问题中将发挥着什么重要作用?
光敏电阻的应用电路
为什么模块化可组合性对当今的安全关键型软件开发至关重要
模块化UPS电源设备的配置
RECOM发布全新的高性价比6W RACM06E-K/277系列AC/DC转换器
崔芳:“5G终端扬帆计划”推进5G行业终端的成熟和发展
泰克MDO3014混合域示波器的性能特点及应用
fireflyROC-RK3308B-CC--启动模式说明
液压比例阀与伺服阀的区别
新一代SimpleLink WiFi产品的解决方案介绍
博敏电子1月至9月实现营业收入19.96亿元
水利水电工程施工常用的测量仪器
如果有一天无处不在的电磁波,那该有多神奇?