How to write c program in Linux?
gccfirst.C-ofirst description:
1>Compile the c source file named first.C in the current directory;
2>In the current directory Next, generate an executable program named first (you can write this name casually, as long as it complies with Linux naming rules); about running: Use the ls-l command, you can see that there is a green file named first in the current directory. It is the file just compiled; it can be run using the command "./first" (no double quotes, double quotes are used for explanation);
How does Linux compile the C source program? gcc, what is the compilation command?
Compilation method: Format The simplest option commonly used by gcc is: gcchello.c will generate an executable file of a.out by default. You only need to enter ./a.out on the terminal. You can see the execution results. If you want to specify the name of the generated target file, you can add the -o option. The command is as follows: gcc-ohellohello.
c command: gcc-chellohello.c
Extended information: Basic usage of gcc command gcc Among them, filenames is the file name; options is the compilation option.
When hello.c is compiled without any compilation options, gcc will automatically compile and generate an a.out executable file: #lshello.c#gcchello.c#lsa.outhello.c execution: #./a.outHello,World!Use the -o compilation option to specify a name for the compiled file: #lsa.outhello.c#gcchello.c-ohello#lsa.outhellohello.cExecute: #./helloHello, World! Note: When using the -o option, -o must be followed by a file name, namely: -ooutfile. In order to facilitate the description of the following options, delete the hello and a.out executable files.
How to write c language program in linux?
First enter vimtest.c in the terminal and press Enter to enter the vim editor, then press the a key to enter the editing state, and then enter the following C language statement:
#includestdio.h >intmain(){printf(helloworld!n);} At this point, press the esc key to exit the editing state, then enter a colon (shift+colon and semicolon key), followed by wq, that is, enter: wq and press Enter. That is, launch the vim editor and return to the terminal command window (similar to the XP command prompt), and then enter gcctest.c. This step is to compile ./a.out. This is execution, and helloworld will be output! This ends, provided that you have installed gcc