Code::Blocks

User forums => Help => Topic started by: Cryptic Maniac on March 12, 2018, 12:13:56 am

Title: Code:Blocks Error
Post by: Cryptic Maniac on March 12, 2018, 12:13:56 am
I am using Windows 10, this is the version of codeblocks that I am using: codeblocks-17.12mingw_fortran-setup.exe

Issue:
When I am trying to compile a Fortran Code in CB, I have a series of errors pop up
Code
! A fortran95 program for G95
! By WQY

program main

  implicit none

  integer re_i

  write(*,*) "Do you work?"

  re_i = system("pause")
end

Errors
||=== Build: Debug in Fortran Test (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `MAIN__':|
C:\Users\Peter\Documents\Coding\Fortran Test\main.f95|10|undefined reference to `_gfortran_st_write'|
C:\Users\Peter\Documents\Coding\Fortran Test\main.f95|10|undefined reference to `_gfortran_transfer_character_write'|
C:\Users\Peter\Documents\Coding\Fortran Test\main.f95|10|undefined reference to `_gfortran_st_write_done'|
C:\Users\Peter\Documents\Coding\Fortran Test\main.f95|11|undefined reference to `_gfortran_st_write'|
C:\Users\Peter\Documents\Coding\Fortran Test\main.f95|11|undefined reference to `_gfortran_transfer_character_write'|
C:\Users\Peter\Documents\Coding\Fortran Test\main.f95|11|undefined reference to `_gfortran_transfer_character_write'|
C:\Users\Peter\Documents\Coding\Fortran Test\main.f95|11|undefined reference to `_gfortran_transfer_character_write'|
C:\Users\Peter\Documents\Coding\Fortran Test\main.f95|11|undefined reference to `_gfortran_transfer_character_write'|
C:\Users\Peter\Documents\Coding\Fortran Test\main.f95|11|undefined reference to `_gfortran_st_write_done'|
C:\Users\Peter\Documents\Coding\Fortran Test\main.f95|13|undefined reference to `_gfortran_system'|
obj\Debug\main.o||In function `main':|
C:\Users\Peter\Documents\Coding\Fortran Test\main.f95|14|undefined reference to `_gfortran_set_args'|
C:\Users\Peter\Documents\Coding\Fortran Test\main.f95|14|undefined reference to `_gfortran_set_options'|
||error: ld returned 1 exit status|
||=== Build failed: 13 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|


I have uninstalled and reinstalled several times but the errors remain.
A mate told me it's linking errors in code blocks as I can use the Console just fine.

On top of that, the debugger also doesn't work.
It skips over breakpoints, doesn't run to cursor, and fails to complete debugging on its own with this error.
At C:\Users\Peter\DOCUME~1\Coding\C__TUT~1\1AA5E~1.11A\main.cpp:22
Cannot open file: watching variables and the call stack)\main.cpp
At watching variables and the call stack)\main.cpp:22


I have been stuck googling solutions to no avail.
Title: Re: Code:Blocks Error
Post by: stahta01 on March 12, 2018, 12:50:24 am
You need to link to a library; I do not do FORTRAN; so, I have no idea what library.

Edit: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

You may need to find an FORTRAN support site and post a build log in order to get help.

Tim S.
Title: Re: Code:Blocks Error
Post by: gd_on on March 12, 2018, 01:22:19 pm
You need to compile your code with gfortran not gcc ... see :
Code: [Select]
||=== Build: Debug in Fortran Test (compiler: GNU GCC Compiler) ===|
look in the wiki how to set up your fortran compiler if it's not already done.
And your file should be named something like main.f or main.f90 or main .f95, but you have :
Code: [Select]
C:\Users\Peter\DOCUME~1\Coding\C__TUT~1\1AA5E~1.11A\main.cppgd_on
Title: Re: Code:Blocks Error
Post by: BentL on March 12, 2018, 02:47:25 pm
You need to configure your Fortran project properly. The best way to start a new Fortran project is to use the "Fortran application" template:

File > New > Project... > Projects > Fortran application > Go

This way all necessary settings needed for a Fortran project are applied.

But you can also manually set these settings.


1) First set the compiler:

File > Settings... > Compiler... > Global compiler settings > Selected compiler: GNU Fortran Compiler

Then the toolchain:

File > Settings... > Compiler... > Global compiler settings > Toolchain executables > Program files

with the settings:

C compiler: mingw32-gfortran.exe
C++ compiler: mingw32-gfortran.exe
Linker for dynamic libs: mingw32-gfortran.exe
Linker for static libs: ar.exe
Debugger: GDB/CDB debugger : default
Resource compiler: windres.exe
Make program: mingw32.make.exe


2) Next you can configure the debugger:

Settings > Debugger... > GDB/CDB debugger > Default > Executable path > C:\Program Files (x86)\CodeBlocks\MinGW\bin\gdb32.exe

and select GDB as debugger.


3) Next you can specify that all libraries should be statically linked to the exe-file, so the application contains just one file:

File > Project > Build options... > Select application name > Linker settings > Other linker options > -static


4) Finally, you need to update the file "libgfortran-3.dll" as described in this post (http://forums.codeblocks.org/index.php/topic,22354.msg152932.html#msg152932) in order to work with files.
Title: Re: Code:Blocks Error
Post by: Cryptic Maniac on March 12, 2018, 07:41:04 pm
Thank you very much,
I feel very foolish not realising that building Fortran with GNU GCC settings doesn't make it work.
Although when I can't compiler it also didn't work.

C++ and Fortran now run thanks to you wonderful people.
However, I am still having trouble with the Debugger, even after following your instructions.

It still ignores Breakpoints.

'Run to Cursor' causes the debugger to crash. Luckily not C::B though.

'Step out' function brings up this error
Debugger name and version: GNU gdb (GDB) 7.9.1
Child process PID: 11460
At C:\Users\Peter\Documents\Coding\C++ Tutorials\1.11a Debugging your program (watching variables and the call stack)\main.cpp:22
Cannot open file: watching variables and the call stack)\main.cpp
At watching variables and the call stack)\main.cpp:22

I know it's the same error.  :(
Title: Re: Code:Blocks Error
Post by: BentL on March 13, 2018, 01:40:50 pm
However, I am still having trouble with the Debugger, even after following your instructions.

You need to produce debugging symbols for your project for debugging to work.

File > Project > Build Options... > Your application name > Debug > Compiler flags > Debugging > Produce debugging symbols > Check

See also the wiki for how to debug in Code::Blocks:
http://wiki.codeblocks.org/index.php?title=Debugging_with_Code::Blocks