Integrated Development Environments:
kdevelop is an Integrated Development Environment (IDE) similar
to IDE's found under Windows. Describing kdevelop is beyond the scope
of this document. You can find more information at http://www.kdevelop.org
Editorsi:
There are many editors available for Linux. If you're actually in
the lab, I urge you to use one of the graphical editors available.
There are two in the "K" desktop environment. You can find them under
the "K" Menu at the bottom-left of the screen.
1) kedit is a simple graphical editor that is similar in
function to Windows "Notepad".
2) kwrite is a more powerful graphical editor that is similar
in function to Windows "Write". However, it can colorize your source
code to make editing easier. For example, comments in red, strings
in blue, etc.
If you're telnet-ing in, there are three text-based editors
to choose from:
1) pico is a simple editor that many beginning Linux users
choose. It's quite simple to use and intuitive to understand.
2) vi is the workhorse of Unix. It is a "home" key
editor, meaning that your hands never leave the keyboard "home" position.
It does not support a mouse, but the cursor keys may work.
A
quick reference for the most common commands can be found by clicking here.
3) emacs is a very powerful editor. It is completely
programmable and can do lots of cool stuff for you. Click
here for a quick reference for emacs.
Compiling:
Now that you've got your source code in a file, you are ready to compile.
The C++ compiler under Linux is called g++. To use it, type
the following:
g++ -Wall -o exec_name source.cpp ...
Where exec_name is replaced with the name of the executable
file that will be created and source.cpp is replaced with
the name of your source code. Note, you can list as many .cpp
files as you like. The -Wall option says to turn on all
warnings. Remove the option if it gets annoying.
Note: Do not name your program test. test is
a program in /bin that is used in Bourne shell programming.
Instead, name your executable mytest or something more meaningful.
Separate Compilation:
If you separate your source code into many small files, you should compile
each of them separately and link them together to form the executable.
This approach enables you to compile only those files that you've changed,
rather than compiling every line of code every time. You can do this
by hand with the following commands.
g++ -Wall -c source1.cpp
g++ -Wall -c source2.cpp
...
The -c option means "compile only". An executable will not
be created. Rather, a binary object (.o) file is created.
Once you compile all your files, you can link them together into an
executable with either of these commands:
g++ -o exec_name source1.o source2.o
OR
g++ -o exec_name *.o
The last line works if you want to combine all the .o files in the current
directory.
This process can be automated with the make utility.
A very simple Makefile can be found by clicking here.
Once you create and edit this file, all you have to do is type "make"
at the command line.
Executing:
Just type the name of your executable at the command-line. You may
have to preface the executable with "./" if "." isn't
in your path. For example...
$ mytest if this doesn't work...
bash: mytest: command not found
$ ./mytest then try this
Debugging:
The debugger under Linux is called "gdb" (for Gnu DeBugger).
Type gdb exec_name to start it. See the man
page for more information or click here for a gdb quick
reference. Note: You have to compile with the -g option to use
the debugger.
|