如何在Ubuntu中安装CC编译器和开发工具
许多Linux工程师需要使用一些通用的编程语言来自动化其正常任务。本文介绍了如何安装C和C ++编译器及其开发工具(必需的构建工具)以及相关的软件包,例如make,libc-dev,dpkg- dev等在Linux中。
在进入安装部分之前,最好先了解一下编译器。
“编译器是一种软件程序,用于处理以特定编程语言编写的语句并创建二进制文件,机器的CPU可以轻松地理解并执行它们”
安装C,C ++编译器和开发工具
如果您的系统中未安装Build-Essential Tools,请使用以下命令-
$ sudo apt-get install build-essential
输出应该是这样的–
Reading state information... DoneThe following packages were automatically installed and are no longer required:
gcc-4.8-base:i386 libasn1-8-heimdal:i386 libasound2:i386
libasound2-plugins:i386 libasyncns0:i386 libavahi-client3:i386
libavahi-common-data:i386 libavahi-common3:i386 libbit-vector-perl
libcapi20-3:i386 libcarp-clan-perl libclass-method-modifiers-perl
libcups2:i386 libdata-random-perl libdate-calc-perl libdate-calc-xs-perl
libdrm-amdgpu1:i386 libdrm-intel1:i386 libdrm-nouveau2:i386
libdrm-radeon1:i386 libedit2:i386 libelf1:i386 libexif12:i386 libexpat1:i386
libffi6:i386 libflac8:i386 libfontconfig1:i386 libfreetype6:i386
libgcrypt11:i386 libgd-perl libgd3:i386 libgif4:i386
libgl1-mesa-dri-lts-wily:i386 libgl1-mesa-glx-lts-wily:i386
libglapi-mesa-lts-wily:i386 libglib2.0-0:i386 libglu1-mesa:i386
libgnome2-gconf-perl libgnutls26:i386 libgpg-error0:i386 libgphoto2-6:i386
libgphoto2-port10:i386 libgssapi-krb5-2:i386 libgssapi3-heimdal:i386
libgstreamer-plugins-base0.10-0:i386 libgstreamer0.10-0:i386
libhcrypto4-heimdal:i386 libheimbase1-heimdal:i386 libheimntlm0-heimdal:i386
libhx509-5-heimdal:i386 libice6:i386 libieee1284-3:i386
libjack-jackd2-0:i386 libjbig0:i386 libjpeg-turbo8:i386 libjpeg8:i386
libk5crypto3:i386 libkeyutils1:i386 libkrb5-26-heimdal:i386 libkrb5-3:i386
libkrb5support0:i386 liblcms2-2:i386 libldap-2.4-2:i386 libllvm3.6:i386
libltdl7:i386 libmouse-perl libmpg123-0:i386 libnet-dropbox-api-perl
libogg0:i386 libopenal1:i386 liborc-0.4-0:i386 libosmesa6:i386
libp11-kit-gnome-keyring:i386 libp11-kit0:i386 libpciaccess0:i386
........................
加快C和C ++编译速度
我们应该删除旧的缓存文件以加快编译速度。要安装缓存管理工具,请使用以下命令-
$ sudo apt-get install aptitude
输出应该是这样的–
Reading package lists... DoneBuilding dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
gcc-4.8-base:i386 libasn1-8-heimdal:i386 libasound2:i386
libasound2-plugins:i386 libasyncns0:i386 libavahi-client3:i386
libavahi-common-data:i386 libavahi-common3:i386 libbit-vector-perl
libcapi20-3:i386 libcarp-clan-perl libclass-method-modifiers-perl
libcups2:i386 libdata-random-perl libdate-calc-perl libdate-calc-xs-perl
libdrm-amdgpu1:i386 libdrm-intel1:i386 libdrm-nouveau2:i386
libdrm-radeon1:i386 libedit2:i386 libelf1:i386 libexif12:i386 libexpat1:i386
libffi6:i386 libflac8:i386 libfontconfig1:i386 libfreetype6:i386
libgcrypt11:i386 libgd-perl libgd3:i386 libgif4:i386
libgl1-mesa-dri-lts-wily:i386 libgl1-mesa-glx-lts-wily:i386
libglapi-mesa-lts-wily:i386 libglib2.0-0:i386 libglu1-mesa:i386
libgnome2-gconf-perl libgnutls26:i386 libgpg-error0:i386 libgphoto2-6:i386
libgphoto2-port10:i386 libgssapi-krb5-2:i386 libgssapi3-heimdal:i386
libgstreamer-plugins-base0.10-0:i386 libgstreamer0.10-0:i386
libhcrypto4-heimdal:i386 libheimbase1-heimdal:i386 libheimntlm0-heimdal:i386
libhx509-5-heimdal:i386 libice6:i386 libieee1284-3:i386
libjack-jackd2-0:i386 libjbig0:i386 libjpeg-turbo8:i386 libjpeg8:i386
libk5crypto3:i386 libkeyutils1:i386 libkrb5-26-heimdal:i386 libkrb5-3:i386
libkrb5support0:i386 liblcms2-2:i386 libldap-2.4-2:i386 libllvm3.6:i386
libltdl7:i386 libmouse-perl libmpg123-0:i386 libnet-dropbox-api-perl
libogg0:i386 libopenal1:i386 liborc-0.4-0:i386 libosmesa6:i386
libp11-kit-gnome-keyring:i386 libp11-kit0:i386 libpciaccess0:i386
libpulse0:i386 libroken18-heimdal:i386 libsamplerate0:i386 libsane:i386
libsasl2-2:i386 libsasl2-modules:i386 libsasl2-modules-db:i386 libsm6:i386
libsndfile1:i386 libspeexdsp1:i386 libsqlite3-0:i386 libssl1.0.0:i386
libstdc++6:i386 libtasn1-6:i386 libtiff5:i386 libtxc-dxtn-s2tc0:i386
libusb-1.0-0:i386 libv4l-0:i386 libv4lconvert0:i386 libvorbis0a:i386
...................................
现在使用aptitude安装ccache工具,如下所示–
$ sudo aptitude install ccache
样本输出应如下所示–
The following NEW packages will be installed:ccache
The following packages will be REMOVED:
gcc-4.8-base:i386{u} libasn1-8-heimdal:i386{u} libasound2:i386{u}
libasound2-plugins:i386{u} libasyncns0:i386{u} libavahi-client3:i386{u}
libavahi-common-data:i386{u} libavahi-common3:i386{u}
libbit-vector-perl{u} libcapi20-3:i386{u} libcarp-clan-perl{u}
libclass-method-modifiers-perl{u} libcups2:i386{u} libdata-random-perl{u}
libdate-calc-perl{u} libdate-calc-xs-perl{u} libdrm-amdgpu1:i386{u}
libdrm-intel1:i386{u} libdrm-nouveau2:i386{u} libdrm-radeon1:i386{u}
libedit2:i386{u} libelf1:i386{u} libexif12:i386{u} libexpat1:i386{u}
libffi6:i386{u} libflac8:i386{u} libfontconfig1:i386{u}
libfreetype6:i386{u} libgcrypt11:i386{u} libgd-perl{u} libgd3:i386{u}
libgif4:i386{u} libgl1-mesa-dri-lts-wily:i386{u}
libgl1-mesa-glx-lts-wily:i386{u} libglapi-mesa-lts-wily:i386{u}
libglib2.0-0:i386{u} libglu1-mesa:i386{u} libgnome2-gconf-perl{u}
libgnutls26:i386{u} libgpg-error0:i386{u} libgphoto2-6:i386{u}
libgphoto2-port10:i386{u} libgssapi-krb5-2:i386{u}
libgssapi3-heimdal:i386{u} libgstreamer-plugins-base0.10-0:i386{u}
.........................................
使用示例程序测试C和C ++
例如,要测试C程序,请创建一个名为sum .c的文件,并添加以下命令-
#includeint main(){
int a, b, c;
printf("Enter two numbers to add: ");
scanf("%d%d",&a,&b);
c = a + b;
printf("The sum of two numbers equals %d\n",c);
return 0;
}
上面的命令给出两个数字之和的结果。要将上述代码编译为当前工作目录中名为sum的可执行文件,请使用-o开关和gcc –
$ gcc sum.c -o sum
要使用ccache命令,请使用以下命令-
$ ccache gcc sum.c -o sum
要运行二进制命令,请使用以下命令–
$ ./sum
样本输出应如下所示–
$ ./sumEnter two numbers to add: 24 54
The sum of equals 78
恭喜你!现在,您知道“如何在Ubuntu中安装C,C ++编译器和开发工具”。在我们的下一篇Linux文章中,我们将详细了解这些类型的命令。继续阅读!
以上是 如何在Ubuntu中安装CC编译器和开发工具 的全部内容, 来源链接: utcz.com/z/347338.html