PDA

View Full Version : Gcc?



Witch_King
09-19-2001, 07:16 PM
If I install RedHat 7.0 and actually get the thing working, how do I start using gcc? How do I activate the editor, what is the name of the editor? And what are the commands to first compile and build my executable? What are the steps to creating a program after all the code is written? Do I need to create a make file? Is this done on the command line? Is the whole process a really big pain?

Nick
09-19-2001, 09:56 PM
I use emacs and I have something like



(setq auto-mode-alist
(append '(("\\.C$" . c++-mode)
("\\.cc$" . c++-mode)
("\\.cpp$" . c++-mode)
("\\.h$" . c++-mode)
("\\.hh$" . c++-mode)
("\\.idl$". c++-mode)
("\\.c$" . c-mode))
auto-mode-alist))

(add-hook 'c-mode-common-hook
'(lambda ()
(setq indent-tabs-mode nil)
(c-set-style "stroustrup")))

(global-font-lock-mode t)
(lazy-lock-mode t)

in my ~/.emacs

If just compiling one file you can do something like
g++ foo.cc -Wall for c++

Unregistered
09-20-2001, 04:10 PM
Or just use a visual IDE with gcc, like KDevelop or whatever (there are many). Then it is just like it is in Windows.

Flarelocke
09-21-2001, 06:00 PM
how do I start using gcc? $gcc inputfile.c -o executablename -lstdc++

$ represents a command prompt. Some people use % instead
How do I activate the editor, what is the name of the editor?There are two popular editors, and a few less popular editors. The two most popular ones are vi and emacs.

vi~=notepad
emacs~=Word, but that uses primarily plaintext

"$vi name" creates name if name does not exist. RH7's vi is a symlink to vim, which is slightly different."$emacs name" creates name if name does not exist. Emacs is primarily an X application(read: windows program), whereas vi is more of a console program(read: dos program).
And what are the commands to first compile and build my executable? "$gcc inputfilename -o executablename -llibraryname" builds inputfilename into an executable called executablename using the library libraryname, where libraryname is found in /usr/lib/liblibraryname.so, or /lib/liblibraryname.so
What are the steps to creating a program after all the code is written? Just gcc it. Gcc commandlines can get pretty hairy for anything more than a simple test program. To make it easier, make and makefiles were invented. I don't know anything about using makefiles.
Do I need to create a make file?No, but for larger programs you will want to eventually.
Is this done on the command line? Is the whole process a really big pain?Yes it's all done on the command line if you separate the editor from the compiler, which emacs does not do. There's an emacs mode that gives you a shortcut key to compile the current file, and other such things. It's not a big pain. People do it all the time. The overhead of a makefile is a one-time thing, and really speeds up the project once done. autoconf and automake make the overhead even less per project, but there's a one-time overhead in learning how to use them, which isn't trivial.(You could probably learn it in 24 hours or so if you had some projects for which you need to make some makefiles, but I don't, so learning on a purely abstract basis is rather difficult)