Linux下面如何进行C语言编程(国外英文资料)
Linux下面如何进行C语言编程(国外英文资料)
Compile the source program
Under Linux, if you want to compile a C source program, we will use GNU's GCC compiler. Here is an example
How to use the GCC compiler.
Suppose we have the following very simple source program (hello.c) :
Int main (int argc, char * * argv)
{
Printf (" Hello Linux \ n ");
}
To compile this program, we simply execute on the command line:
GCC -o hello hello. C
GCC compiler will generate a hello executable files for us.. / hello, you can see the output of the program. The command line to GCC says we are in GCC to compile the source program, we -o said we ask the compiler to give us the output of an executable file named hello, hello. Is our c source program files.
GCC compiler has many options, generally we only know a few of them will be enough. -o option we already know, said we require the output of the executable file name. The -c option said we only request object code compiler output, output and unnecessary executable file. The -g option said we are asking the compiler when compiling information after we debug the program.
Know the three options, we can build our own source program written in simple, if you want to know more options, you can view the GCC documentation, there are many details of other options.
2. Write a Makefile
Suppose we had a program like this, source code as follows:
/ *...
# include "mytool1. H"
# include "mytool2. H"
Int main (int argc, char * * argv)
{
Mytool1_print (" hello ");
Mytool2_print (" hello ");
}
/ * mytool1.h * /
# # ifndef _MYTOOL_1_H
# define _MYTOOL_1_H
Void mytool1_print (char * print_str);
# endif
/ * mytool1.c * /
# include "mytool1. H"
Void mytool1_print (char * print_str)
{
Printf (" This is mytool1 print % s \ n ", print_str);
}
/ * mytool2.h * /
# # ifndef _MYTOOL_2_H
# define _MYTOOL_2_H
Void mytool2_print (char * print_str);
# endif
/ * mytool2.c /
# include "mytool2. H"
Void mytool2_print (char * print_str)
{
Printf (" This is mytool2 print % s \ n ", print_str);