>>набираешь код в любом txt редакторе как тут уже правильно сказали, сохраняешь
>>его, в фомате *.с (например example.c)
>>в консоли пишешь
>А сохранять куда угодно?
>Это компиляция, а как посмотреть результаты(run, build, exec...etc)?
(Sorry for typing in English, here in Canada it's hard to come by a cyrillized keyboard. If russian text is desirable, just let me know, I will try to provide russian translation ;)
OK, here is a quick rundown for struggled former MSDOS developers.
1. Create a directory for your project:
2. Go to this directory and create source file:
(or 'xemacs source1.c', or 'vi source1.c', or use any other text editor that you like)
3. After you save the file in the editor and exit from the editor, compile the source file:
4. If the compilatin/linking is successful, you will get file 'a.out' that is an executable of your program. Run it by typing:
(note the ./ that is pre-pended to the name of the executable, that could seem unusual for MSDOS developers: normally, for security reasons, Unix environment is set up so the PATH env. variable does not contain a current directory (you can check 'echo $PATH' to see if this is true on your system), so just typing 'a.out' will not find the executable you've just build. So you'll need to type ./ to indicate to shell that you want to execute file 'a.out' that is located in the curernt dyrectory)
That's basically all that it is in compiling/building a program which source consists of one file, in our case, source1.c.
Now optional features:
a) If you want the executable program to be named something else then 'a.out', you use option '-o <exe_name>' of the compiler:
gcc source.c -o program
will create executable file 'program', that you can run by typing
(note that in Unix executable file normally does not have extention .exe, in fact, they normally do not have extension at all)
b) If your program consist from more then one source file, you can just list them all in the command line, like this:
gcc source1.c source2.c source3.c -o program
- this command will compile three source files and build an executable file 'program'
Or you could compile the source files separately into .o object files - in this case, use flag '-c' to prevent a compiler from executing linking when compiling individual source files - and then link all resulting object files into the executable file:
gcc -c source1.c
gcc -c source2.c
gcc -c source3.c
- this will create object files source1.o, source2.o and source3.o;
gcc source1.o source2.o source3.o -o program
- this will create executable file 'program'.
If you want to be able to write serious programs with large number of source files in Unix environment, you should really learn 'make' utility. You create a Makefile - file with the description of the source file dependencies and instructions how to build the executable program from them, and 'make' will analyse the dependancies and compile/build only the source files that were changed since previous compile. In some sence, Makefile is an analogue to the 'project file' of various IDE MSDOS developers are used to.
Also, some tools like GNU autoconf/automake, Imake or makedepend, that scan your source tree and build Makefiles with dependencies for you automatically, could be of help.
(Additional note: I admit the possibility that all you really wanted was not to know how to write your own programs, but just to ask how to compile/build a program which source you already have in the .tar.gz archive. Un-archive the archive (see 'man tar', 'man gzip' for details, but usually simple 'tar xvfz file.tar.gz' will suffice), then check if the root directory of the program's source code contains file 'configure'. If yes, run following sequence:
- if no errors or missed dependencies were detected, this should build the program. Then, if you want to install the program, become a 'root' and run 'make install'.
If the distributin does not contain a 'configure' file - there should be something, like 'README' or 'INSTALL' file with the instructions how to build.)