Docs
Contents
Start working with C::B
Video tutorials on YouTube, which show how to start using C::B for programming in Fortran:
Code::Blocks IDE for Fortran: First steps (Windows)
Code::Blocks IDE for Fortran: First steps (Linux)
Installation
Just extract downloaded archive with Code::Blocks in your favored directory. Avoid non-english characters on the path. To launch Code::Blocks run "codeblocks.exe" (on Win) or "codeblocks_run.sh" (on Linux). If you have another Code::Blocks distribution on your system you may want to start Code::Blocks as a portable app by executing startup script "codeblocks_portable.bat" ("codeblocks_run_portable.sh"). Code::Blocks saves all settings in installation directory if you launch program using "codeblocks_portable.bat" ("codeblocks_run_portable.sh").
Prerequest
To be able to compile your Fortran files you should have an installed Fortran compiler (gfortran or another one). Windows users first should install MinGW on their system. I would suggest you to install one from MinGW-W64.
Linux users should have 'gtk3' and 'xterm' installed on their system. Linux versions were tested on several recent distributions.
Setup of compiler's installation directory (gfortran users)
Windows users may need to help Code::Blocks to find MinGW and Fortran compiler on their system. Short instruction:
In Code::Blocks open "Settings -> Compiler..." dialog. Find "GNU GCC Compiler". Open "Toolchain executables" tab. Fill "Compiller's installation directory" text-box (in my case it is C:\MinGW32).
For gfortran compiler. Find "GNU Fortran Compiler". Open "Toolchain executables" tab. Fill "Compiller's installation directory" text-box (in my case it is C:\MinGW32) and "Program Files" text-boxes. Just remember, that programs on Windows end with ".exe". So your compiler name should end with ".exe" too.
The same procedure is applicable for other compilers/OS.
How to setup Intel Fortran compiler on Windows
If you are going to use commercial Intel Fortran compiler on Windows, first you should help C::B to find compiler executable file (Note: I said "compiler", not "debugger". There is no support of the debugger for this compiler on Windows). To do so, in C::B go to "Settings->Compiler”, select Intel Fortran Compiler for Windows. Go to “Toolchain executables” tab. Here you should fill “Compiler’s installation directory” text field. For example C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\bin\intel64
. "C compiler", "C++ compiler" and "Linker for dynamic libs" text fields should be filled with "ifort.exe".
Second problem: environment variables. As is recommended by Intel in documentation, to setup environment variables it is required to execute ‘compilervars.bat’ file in cmd window. You can create the "codeblocks_run.bat" file in the Code::Blocks directory with following content:
@call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat" @start codeblocks.exe
Doubleclicking on "codeblocks_run.bat" will start C::B.
Note: to be able to run your compiled program from inside of C::B you should install MinGW on your system and setup GCC compiler’s installation directory on "Settings->Compiler”, “Toolchain executables” tab.
How to setup Intel Fortran compiler on Linux
BindTo tool
BindTo (Fortran->Bind To…) automatically generates a wrapping for Fortran code which enables call of Fortran from the C language and can generate Cython files which enables call of Fortran from Python language. Read BindTo User Guide
Debugging Fortran code
Code::Blocks IDE is distributed together with the Debugger plugin, which supports the GDB debugger. From within the IDE users can conveniently start GDB session and go line-by-line through the code execution path. More information about debugging in C::B can be found in Debugging Fortran code in the Code::Blocks IDE.
FTL in Code::Blocks
The Fortran Template Library (FTL) is a general purpose library that implements generic containers, easy string manipulation and more. It heavily relies on the C Pre-Processor (PP) directives (#include "Afile", #define B etc.). The use of the PP makes it difficult for the Code::Blocks to parse the library code. Only in CBFortran v1.8, the PP parsing was considerably improved, which enabled to have the code-completion for the FTL. Read tutorial how to use FTL in Code::Blocks.
MPI in Code::Blocks
If you are using MPI, you can build your code from inside of C::B. You just need to adjust your compiler settings to use "mpif90" compiler (Settings->Compiler). See a screenshot:
GTK-Fortran with Code::Blocks
Gtk+ (www.gtk.org) is a cross-platform toolkit for creating Graphical User Interfaces (GUI). Gtk-fortran enables creation of GUI from Fortran using this toolkit. I tried to build few gtk-fortran examples on Windows 7 64bit. This is my instructions / notes how to use gtk-fortran on Code::Blocks. I hope it will be useful for users of C::B. (read full story on Gtk-Fortran )
MathGL + GTK + Fortran
MathGL library can be used for visualisation of calculation results directly in GTK window. Examples, which show how to use this library, are described in MathGL + GTK + Fortran.
Building C::B for Fortran from source files
In some cases (for example there is no binaries for your system) you may want to build C::B for Fortran from source files. To do it, I would recommend you first to build official C::B on your system. How to do it, you can find on the C::B wiki site (http://wiki.codeblocks.org). When you have the compiled official C::B running on your system, you can download C::B for Fortran source file archive. Some files in archive have small changes compared to official sources. Unarchive downloaded file and build C::B. You should use your running C::B as is described on Wiki for Windows OS (here). If your OS is not Windows, then use 'CodeBlocks-unix.workspace' or 'CodeBlocks-unix.cbp' and 'ContribPlugins-unix.workspace' and 'update' files instead. Because you have compiled the official C::B, you should have all the required dependencies and the compilation procedure should run without problems. FortranProject plugin comes between other contrib plugins ("<C::B_src_dir>/src/plugins/contrib/FortranProject") and is compiled with other contrib plugins. If not, open 'FortranProject_cbsvn-unix.cbp' C::B project file (if you are on Linux) or 'FortranProject_cbsvn.cbp' (if you are on Windows) and compile it. Run 'update' (or 'update.bat') once more.