Author Topic: Code:Blocks Error  (Read 66574 times)

Offline Cryptic Maniac

  • Single posting newcomer
  • *
  • Posts: 2
Code:Blocks Error
« 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.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Code:Blocks Error
« Reply #1 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.
« Last Edit: March 12, 2018, 01:37:20 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline gd_on

  • Lives here!
  • ****
  • Posts: 796
Re: Code:Blocks Error
« Reply #2 on: March 12, 2018, 01:22:19 pm »
You need to compile your code with gfortran not gcc ... see :
Code
||=== 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
C:\Users\Peter\DOCUME~1\Coding\C__TUT~1\1AA5E~1.11A\main.cpp
gd_on
Windows 11 64 bits (23H2), svn C::B (last version or almost!), wxWidgets 3.2.4 (tests with 3.3), Msys2 Compilers 13.2.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\msys64\mingw64) or 32 bits (dwarf2, posix  in C:\msys64\mingw32).

Offline BentL

  • Single posting newcomer
  • *
  • Posts: 8
Re: Code:Blocks Error
« Reply #3 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 in order to work with files.

Offline Cryptic Maniac

  • Single posting newcomer
  • *
  • Posts: 2
Re: Code:Blocks Error
« Reply #4 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.  :(

Offline BentL

  • Single posting newcomer
  • *
  • Posts: 8
Re: Code:Blocks Error
« Reply #5 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

adarsh

  • Guest
Re: Code:Blocks Error
« Reply #6 on: September 06, 2019, 08:46:22 am »
Thank you.The above changes worked for me. Although it is showing one more error" You must select a host application to 'run' a library.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Code:Blocks Error
« Reply #7 on: September 06, 2019, 06:05:07 pm »
What is the type of application you've selected for your target in Project -> Properties -> Build targets -> your target -> Build type? I guess it is set to dynamic library. It should be set to native or console in order to work. Of course if you're making an application. If you're making a dll/static library then you'll need a host.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]