Geju on Rare Linux is a published version, the typical Linux release version includes the Linux kernel, desktop and a variety of common essential tools, the international use of more is Ubuntu (Bantu), CentOS, Deepin (Deep Linux). This tutorial takes Deepin as an example to tell how to compile a C program.
Gedit
Gedit is a complex and adaptable text editor with a beautiful interface that supports syntax highlighting and is easier to get started than Vim. This tutorial will gedit as a C code editor.
Gedit Device:
sudo apt-add-repository ppa:ubuntu-on-rails/ppa//Add Ubuntu software source sudo apt-get update//Update software list sudo apt-get install gedit -gmate//Device
Create a C source file under the next catalog and turn it on:
Touch Test.cgedit test.c
You can see the gedit window, output:
#include <stdio.h> #include <stdlib.h> int main () {printf ("hello,linux.\n"); exit (0);}
650) this.width=650; "src=" Http://c.biancheng.net/cpp/uploads/allimg/140830/1-140S013013E38.png "style=" border:0 px;width:652px;height:533px; "/>
Gedit window
Note: Gedit support a variety of speech highlighting, the general situation can be active to identify the language, if the identification of the problem, please select the "compilation---highlighting form" under C.
Gcc
Linux is the most common use of the C + + compiler is GCC, most of the Linux published version of the tacit device, whether it is to open up the same beginner, the general will be GCC as the preferred compilation tool under Linux. This tutorial has no hesitation in using GCC to compile C programs.
keep the documents in and out, open the terminal and CD to the later contents, output the following royal decree:
gcc test.c-o Test
you can link C code compilation directly to the executable file.
you can see a file test in the next catalog, which is the executable file. Unlike Windows,linux, which does not use file suffixes to identify executable files, the executable suffix under Linux can actually be changed arbitrarily.
of course, you can also compile it in steps:
1) Pre-disposal
gcc-e test.c-o test.i
in the future under the content will be more than a pre-disposition consequences file Test.i, opened Test.i can see, in the test.c on the basis of stdio.h and stdlib.h the contents of the plug out.
2) Compile as assembly code
gcc-s test.i-o Test.s
The- s parameter is the completion step in the compilation, and-O for the specified file name.
3) Assembly for the purpose of the document
gcc-c test.s-o TEST.O
. O is the destination file. The purpose file is similar to the executable file, which is a machine-readable executable code, but because there is no link, the structure will be slightly divided.
3) Link and generate the executable file
gcc test.o-o Test
If there are multiple source files, you can compile as promises:
gcc-c test1.c-o test1.o
gcc-c test2.c-o test2.o
gcc test1.o test2.o-o test
Note: If you do not specify a filename, GCC will generate a file named A.out. Out file is only to identify the compiled file, Linux does not have a standard executable file suffix name, the normal executable file does not have a suffix name.
The test file generated after compilation is the program that runs it:
./test
If you do not have permission to operate, you can use the sudo royal order to add permissions (note the Linux partition):
sudo cdmod test 777
we can use the-pedantic,-wall,-werror options for the error checking of the program:
The-pedantic option helps programmers find code that does not fit the Ansi/iso C specification (not all);
-wall can let GCC display warn message;
-werror allows GCC to abort when it encounters problems in the compilation.
Many of these 3 options are very effective.
This article is from the "11999725" blog, please be sure to keep this source http://12009725.blog.51cto.com/11999725/1843289
Running C speech program under Linux