Difference between revisions of "Fortran support in Code::Blocks"

From Code::Blocks
 
Line 1: Line 1:
 
== Attaching the compiler framework ==
 
== Attaching the compiler framework ==
To attach the GNU Fortran 77 Compiler (G77) the following steps are required:
+
To attach the GNU Fortran 77 Compiler (G77) the following steps are required:\\
1.) Make a copy of the GNU GCC compiler
+
1.) Make a copy of the GNU GCC compiler\\
 
- Goto menu "Settings" -> "Compiler"
 
- Goto menu "Settings" -> "Compiler"
 
- Select the "GNU GCC Compiler", click the "Copy Button"
 
- Select the "GNU GCC Compiler", click the "Copy Button"
- Save the copy e.g. under "GNU G77 Compiler"
+
- Save the copy e.g. under "GNU G77 Compiler"\\
2.) Setup the compiler as following:
+
2.) Setup the compiler as following:\\
 
- The path etc. should be as of the GCC Compiler. If this has been setup correctly, no changes are required. Otherwise refer to the setup of the GNU GCC compiler.
 
- The path etc. should be as of the GCC Compiler. If this has been setup correctly, no changes are required. Otherwise refer to the setup of the GNU GCC compiler.
 
- Change under the "Programs" tab: "C compiler" =  "g77.exe", "Linker for dynamic libs": "g77.exe"
 
- Change under the "Programs" tab: "C compiler" =  "g77.exe", "Linker for dynamic libs": "g77.exe"
- In the "Linker" tab add "-lg2c" (and "-lstdc++" if you have mixed Fortran/C++ projects) under "Other linker options".
+
- In the "Linker" tab add "-lg2c" (and "-lstdc++" if you have mixed Fortran/C++ projects) under "Other linker options".\\
 
3.) Important: Make sure the path environment is setup to really point a path that contains the Fortran compiler suite. C::B with MinGW does '''NOT''' include the Fortran compiler. You may download the compiler under [http:://www.mingw.org]. "gcc-g77-3.4.2-20040916-1.tar.gz" is the name of the package I expect you want.
 
3.) Important: Make sure the path environment is setup to really point a path that contains the Fortran compiler suite. C::B with MinGW does '''NOT''' include the Fortran compiler. You may download the compiler under [http:://www.mingw.org]. "gcc-g77-3.4.2-20040916-1.tar.gz" is the name of the package I expect you want.
  

Revision as of 19:17, 21 November 2005

Attaching the compiler framework

To attach the GNU Fortran 77 Compiler (G77) the following steps are required:\\ 1.) Make a copy of the GNU GCC compiler\\ - Goto menu "Settings" -> "Compiler" - Select the "GNU GCC Compiler", click the "Copy Button" - Save the copy e.g. under "GNU G77 Compiler"\\ 2.) Setup the compiler as following:\\ - The path etc. should be as of the GCC Compiler. If this has been setup correctly, no changes are required. Otherwise refer to the setup of the GNU GCC compiler. - Change under the "Programs" tab: "C compiler" = "g77.exe", "Linker for dynamic libs": "g77.exe" - In the "Linker" tab add "-lg2c" (and "-lstdc++" if you have mixed Fortran/C++ projects) under "Other linker options".\\ 3.) Important: Make sure the path environment is setup to really point a path that contains the Fortran compiler suite. C::B with MinGW does NOT include the Fortran compiler. You may download the compiler under [http:://www.mingw.org]. "gcc-g77-3.4.2-20040916-1.tar.gz" is the name of the package I expect you want.

Adding new Fortran file type

It makes sense to add a new "Fortran Sources" filetype to have the Fortran source code files being seperated. Steps to do so: - Goto menu "Project" -> "Project tree" -> "Edit file types categories" - Click on "Add" to add a new type of files - Select "Fortran Sources" as group name - Enter the following in the file-mask (without quotation marks): "*.f;*.f77;*.cmn;*.inc;" - Click OK to close the dialog. For your interest: "*.f;*.f77" are normally the default extension for source code files, "*.cmn" is the extension for Fortran common-blocks and "*.inc" if often used as include file with e.g. variable declarations.

Setting up Fortran projects

To work with Fortran files, do the following: Add a (new) file to the project, saved as "your_fortran_file.f". Verify it's recognised as "Fortran Sources" file type. If not verify you have done the steps above correctly. To enable compiling the project which includes Fortran files follow these steps: 1.) Right click on the project, select "Build options" and make sure you have selected the "GNU G77 compiler" (see steps above). 2.) Right click on the "your_fortran_file.f" file and select "Properties". - Enable "Compile file" and "Link file". - Under the "Advanced" tab enter "CC" as compiler variable 3.) Compilethe project, it should work by now.

Troubleshooting

For troubleshooting enable the "Full command line" Under menu "Settings" -> "Compiler" -> "Other" tab, "Compiler logging". If you see that still the gcc compiler is invoked, make sure you setup the right compiler in the build options for your project AND your target (e.g. "default").