03.12.2012 Views

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Programming tools<br />

Chapter 10<br />

In this chapter we introduce programming tools that can be used to solve the exercises.<br />

10.1 GCC<br />

GCC stands <strong>for</strong> the Gnu Compiler Collection. It is a collection of compilers (C, <strong>C++</strong>, FOR-<br />

TRAN, Fortran 90, java) free of charge [?]. The <strong>C++</strong> compilers are very good and produce<br />

reasonably efficient code. In this section, we explain how to compile a <strong>C++</strong> program.<br />

The following command:<br />

g++ -o hello hello.cpp<br />

compiles the <strong>C++</strong> source file hello.cpp into the executable hello.<br />

The compiler command is gcc or g++ with the following options.<br />

• -Idirectory: Include files directory<br />

• -O: Optimization<br />

• -g: Debugging<br />

• -p: Profiling<br />

• -o filename: output file name<br />

• -c: Compile, no link<br />

• -Ldirectory: Library directory<br />

• -lfile: Link with library libfile.a<br />

Here is another example:<br />

g++ -o foo foo.cpp -I/opt/include -L/opt/lib -lblas<br />

compiles and links the file foo.cpp using include files from /opt/include/ (option -I) and<br />

linked with a library that is situated in the directory /opt/lib: For optimizing code, we have<br />

to use the compilation options :<br />

-O3 -DNDEBUG<br />

235

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!