The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]

форумы  помощь  поиск  регистрация  майллист  ВХОД  слежка  RSS
"компиляция програм на С"
Вариант для распечатки  
Пред. тема | След. тема 
Форумы Программирование под UNIX (Public)
Изначальное сообщение [Проследить за развитием треда]

"компиляция програм на С" 
Сообщение от morkva emailИскать по авторуВ закладки(ok) on 03-Апр-05, 14:48  (MSK)
Не материтесь, перехожу из винды.
Подскажите где лучше писать свои програмы и как их компилировать с помощью gcc.
  Правка | Высказать мнение | Ответить | Рекомендовать в FAQ | Cообщить модератору | Наверх

 Оглавление

Индекс форумов | Темы | Пред. тема | След. тема
Сообщения по теме

1. "компиляция програм на С" 
Сообщение от morkva emailИскать по авторуВ закладки(ok) on 03-Апр-05, 15:21  (MSK)
>Не материтесь, перехожу из винды.
>Подскажите где лучше писать свои програмы и как их компилировать с помощью
>gcc.


мне кто-то ответит или нет?

  Удалить Правка | Высказать мнение | Ответить | Рекомендовать в FAQ | Cообщить модератору | Наверх

2. "компиляция програм на С" 
Сообщение от kir Искать по авторуВ закладки(??) on 03-Апр-05, 15:25  (MSK)

графические интерфейсы по типу всяких IDE ... как визуал си и всяких делфях отдыхают


набираешь в vi а компилируешь ручками :)


  Удалить Правка | Высказать мнение | Ответить | Рекомендовать в FAQ | Cообщить модератору | Наверх

3. "компиляция програм на С" 
Сообщение от morkva emailИскать по авторуВ закладки(ok) on 03-Апр-05, 15:31  (MSK)
>
>
>графические интерфейсы по типу всяких IDE ... как визуал си и всяких
>делфях отдыхают
>
>
>набираешь в vi а компилируешь ручками :)

вот я и спрашиваю какой командой компилировать???

  Удалить Правка | Высказать мнение | Ответить | Рекомендовать в FAQ | Cообщить модератору | Наверх

4. "компиляция програм на С" 
Сообщение от morkva emailИскать по авторуВ закладки(ok) on 03-Апр-05, 16:29  (MSK)
аууууу ответьте!!!!!!!!!!1
  Удалить Правка | Высказать мнение | Ответить | Рекомендовать в FAQ | Cообщить модератору | Наверх

5. "компиляция програм на С" 
Сообщение от toreo Искать по авторуВ закладки on 03-Апр-05, 17:36  (MSK)
набираешь код в любом txt редакторе как тут уже правильно сказали, сохраняешь его, в фомате *.с (например example.c)
в консоли пишешь

gcc example.c


  Удалить Правка | Высказать мнение | Ответить | Рекомендовать в FAQ | Cообщить модератору | Наверх

6. "компиляция програм на С" 
Сообщение от morkva emailИскать по авторуВ закладки(ok) on 03-Апр-05, 18:24  (MSK)
>набираешь код в любом txt редакторе как тут уже правильно сказали, сохраняешь
>его, в фомате *.с (например example.c)
>в консоли пишешь
>
>gcc example.c

А сохранять куда угодно?
Это компиляция, а как посмотреть результаты(run, build, exec...etc)?

  Удалить Правка | Высказать мнение | Ответить | Рекомендовать в FAQ | Cообщить модератору | Наверх

7. "компиляция програм на С" 
Сообщение от AAA emailИскать по авторуВ закладки on 03-Апр-05, 19:39  (MSK)
>>набираешь код в любом txt редакторе как тут уже правильно сказали, сохраняешь
>>его, в фомате *.с (например example.c)
>>в консоли пишешь
>>
>>gcc example.c
>
>А сохранять куда угодно?
>Это компиляция, а как посмотреть результаты(run, build, exec...etc)?


попробуй начать с kdevelop

  Удалить Правка | Высказать мнение | Ответить | Рекомендовать в FAQ | Cообщить модератору | Наверх

8. "компиляция програм на С" 
Сообщение от elvenic Искать по авторуВ закладки(??) on 04-Апр-05, 01:09  (MSK)
>>набираешь код в любом txt редакторе как тут уже правильно сказали, сохраняешь
>>его, в фомате *.с (например example.c)
>>в консоли пишешь
>>
>>gcc 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:

    mkdir ~/project1

2. Go to this directory and create source file:

    cd ~/project1
    emacs source1.c

    (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:

    gcc source1.c

4. If the compilatin/linking is successful, you will get file 'a.out' that is an executable of your program. Run it by typing:

    ./a.out

(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

    ./program

(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'.

Further directions:

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:

    ./configure
    make

- 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.)


Thank you,

    alex.

    

  Удалить Правка | Высказать мнение | Ответить | Рекомендовать в FAQ | Cообщить модератору | Наверх

9. "компиляция програм на С" 
Сообщение от elvenic Искать по авторуВ закладки(??) on 04-Апр-05, 01:20  (MSK)
PS. Of course, you could use something like kdevelop, kate or anjuta, or even eclipce with C/C++ development option - if you wish to have something that resembles an IDE. I have tried in different times different versions of all of them, but still I find that XEmacs plus automake/autoconf generated Makefiles are the thing I like the most.  (Actually, if I'm not mistaken, kdevelop will happily generate an automake/autoconf project for you, so you are not tied to the kdevelop and can switch to another editor if you wish ;)

  Удалить Правка | Высказать мнение | Ответить | Рекомендовать в FAQ | Cообщить модератору | Наверх

10. "компиляция програм на С" 
Сообщение от morkva emailИскать по авторуВ закладки(ok) on 04-Апр-05, 02:21  (MSK)
Спасибо всем большое. Все работает отлично...
  Удалить Правка | Высказать мнение | Ответить | Рекомендовать в FAQ | Cообщить модератору | Наверх


Архив | Удалить

Индекс форумов | Темы | Пред. тема | След. тема
Пожалуйста, прежде чем написать сообщение, ознакомьтесь с данными рекомендациями.




Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру