Author Topic: Building a Fortran project using .o module files  (Read 389 times)

Offline COQ

  • Multiple posting newcomer
  • *
  • Posts: 11
Building a Fortran project using .o module files
« on: November 06, 2019, 02:33:27 pm »
 Hi everybody,

Sorry for my english but Im french and I'm not accustomed to English writing.
I'm a new user with codeblocks. I would like to build a Fortran Project in which some of the module used are only on the form of .o module files (I don't have the source files of these modules)
My project contain several .f90 files in which the main program and subroutines are defined. I manage to compile all these Fortran files individually but when I try to build, I receive error messages indicating, for example, "undefined reference to __tpflash_MOD_tpflash_gm" refering to the instruction CALL TPflash_gm which is defined in the TPflash.o module files.
Yet the corresponding .o module files are actually present in the compilation directory.

Note that I manage to Build the project when I execute the following Dos command in which the .o modules files are listed at the end of the command :

gfortran.exe  -o bin\Debug\TEST-couple_EC2.exe obj\Debug\CALC_DIFF.o obj\Debug\CALC_THERM.o obj\Debug\INITIALISE_PROGEPI.o obj\Debug\MESH_DIFF.o obj\Debug\THERMO.o obj\Debug\VIEIL_PROGEPI.o gm.o minization_gm_lse.o minization_gm_vse.o properties.o thermodynamics.o TPflash.o TPflash_vle.o

Does anyone know how to specify that these modules files should be taken into account by Code::Block dor the Building ?

Thank by advance for your help.

COQ


Offline gd_on

  • Regular
  • ***
  • Posts: 488
Re: Building a Fortran project using .o module files
« Reply #1 on: November 06, 2019, 02:54:56 pm »
Right click on your project name in management window. Choose build option then the tab "Linker settings". In the right part, "Other linker options" add your .o files. That should work I think, though I've never do like that.

An other way to obtain this :
in the menu Project / Add files, add simply your .o file. They should appear in "Other" and their options simply indicate linking (not compile).
An other trick with fortran module : if you have to compile them, they create a .mod file which should exist before the compilation of your main (or calling subroutine). To be sure it's the right order of compilation, in the properties of the file, simply adjust the priority to a low level.
« Last Edit: November 06, 2019, 03:34:16 pm by gd_on »
Windows 10, svn C::B (last version or almost!), WxWidgets 3.1.3, Compilers 8.1.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\MinGW64) or 32 bits (sjlj, posix in C:\MinGW32).

Offline COQ

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Building a Fortran project using .o module files
« Reply #2 on: November 06, 2019, 04:26:34 pm »
Dear gd_on,

Thank you very much, it now works.
I manage to Build the project but then when I try to "run" the editor explain that "you must select a host application to run a library". What should I do ?

Moreover, in the Build log file the last lines seems strange :
"collect2.exe: error: ld returned 1 exit status"
"Process terminated with status 1 (0 minute(s), 2 second(s))
0 error(s), 0 warning(s) (0 minute(s), 2 second(s))
"

Is there a problem ?

Thank you by advance

COQ



Offline COQ

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Building a Fortran project using .o module files
« Reply #3 on: November 06, 2019, 04:57:43 pm »
Dear,

Actually, it appears that the Build have failed ...
In the "Build messages" : "||=== Build: Debug in CODE-COUPLE (compiler: GNU Fortran Compiler) ===|
||=== Build failed: 0 error(s), 0 warning(s) (0 minute(s), 4 second(s)) ===|
"

This might be due to the following error reported in  "Build Log"
"collect2.exe: error: ld returned 1 exit status"

What is the problem ?

Thank by advance for your help.

COQ

Offline COQ

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Building a Fortran project using .o module files
« Reply #4 on: November 06, 2019, 05:17:36 pm »
Dear,

Actually the problem came from the fact that I both Add Files in the menu "Project / Add files" and also in the "Linker settings".
If I just specify them in the "Linker settings",

But I still have the message "you must select a host application to run a library". What should I do ?

Thank by advance for your help.

COQ

Offline gd_on

  • Regular
  • ***
  • Posts: 488
Re: Building a Fortran project using .o module files
« Reply #5 on: November 06, 2019, 07:21:22 pm »
Without a full build log, it's difficult to help you. May be you set a wrong project : "Fortran library" instead of "Fortran application".
This could gives the message you have, because if finally you have built a library (*.a or *.dll file), it cannot be executed like that.
May be your fortran set configuration is wrong...
May be ... that's all we can say with so few informations.
Windows 10, svn C::B (last version or almost!), WxWidgets 3.1.3, Compilers 8.1.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\MinGW64) or 32 bits (sjlj, posix in C:\MinGW32).

Offline COQ

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Building a Fortran project using .o module files
« Reply #6 on: November 07, 2019, 09:29:29 am »
Dear,

You were right : I set a wrong Project type ("Fortran library" instead of "Fortran application") ..... ;D
It is OK now

Thank you very much

COQ

Offline COQ

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Building a Fortran project using .o module files
« Reply #7 on: November 07, 2019, 03:28:39 pm »
Dear gd_on,

I have another problem ....  ;D
I want to use the debugger.
I have set the right debugging executable in "Setting-->Debugger-->Defaults" to gcc.exe (Debugger type GDB) as adviced
But when I try to start the debugger, i receive the attached Debug report, repeated below

What should I do ?

Thanks by advance

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


"Active debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\Projets_EC2\GTT-2019\SUITE-ETUDE\CODE_COUPLE\code_couple_EC2\
Adding source dir: C:\Projets_EC2\GTT-2019\SUITE-ETUDE\CODE_COUPLE\code_couple_EC2\
Adding file: C:\Projets_EC2\GTT-2019\SUITE-ETUDE\CODE_COUPLE\code_couple_EC2\bin\Debug\CODE-COUPLE-EXE.exe
Changing directory to: C:/Projets_EC2/GTT-2019/SUITE-ETUDE/CODE_COUPLE/code_couple_EC2/.
Set variable: PATH=.;C:\Program Files\gcc\bin;C:\Program Files\gcc\bin\bin;C:\Users\Rémi COQUARD\gcc\bin;C:\Users\Rémi COQUARD\gcc\bin\bin;C:\Program Files\gcc\libexec\gcc\x86_64-w64-mingw32\9.2.0;C:\Users\Rémi COQUARD\gcc\libexec\gcc\x86_64-w64-mingw32\8.3.0;C:\Program Files\Microsoft MPI\Bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\ComposerXE-2011\redist\intel64\mkl;C:\Program Files (x86)\Intel\ComposerXE-2011\redist\intel64\mpirt;C:\Program Files (x86)\Intel\ComposerXE-2011\compiler\lib;C:\Program Files (x86)\Intel\ComposerXE-2011\redist\intel64\compiler;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Microsoft Visual Studio\Common\TOOLS;C:\Program Files\Microsoft Visual Studio\Common\MSDEV98\BIN;C:\Program Files\Microsoft Visual Studio\DF98\BIN;C:\Program Files\Microsoft Visual Studio\VC98\BIN;C:\Program Files (x86)\Intel\Compiler\11.1\065\lib\intel64;C:\Program Files (x86)\Intel\Compiler\11.1\065\mkl\em64t\bin;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\mpirt;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\SIMULIA\Commands;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn;c:\Program Files\Microsoft SQL Server\100\Tools\Binn;c:\Program Files\Microsoft SQL Server\100\DTS\Binn;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn;C:\Program Files\Git\cmd;C:\SIMULIA\Abaqus\Commands;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\gnuplot;C:\Users\Rémi COQUARD\gcc;C:\Program Files\Docker Toolbox;C:\Users\Rémi COQUARD\AppData\Local\Microsoft\WindowsApps
Starting debugger: C:\Program Files\gcc\bin\gcc.exe -nx -fullname -quiet  -args C:/Projets_EC2/GTT-2019/SUITE-ETUDE/CODE_COUPLE/code_couple_EC2/bin/Debug/CODE-COUPLE-EXE.exe
done
Debugger finished with status 1
Selecting target:
Debug
Adding source dir: C:\Projets_EC2\GTT-2019\SUITE-ETUDE\CODE_COUPLE\code_couple_EC2\
Adding source dir: C:\Projets_EC2\GTT-2019\SUITE-ETUDE\CODE_COUPLE\code_couple_EC2\
Adding file: C:\Projets_EC2\GTT-2019\SUITE-ETUDE\CODE_COUPLE\code_couple_EC2\bin\Debug\CODE-COUPLE-EXE.exe
Changing directory to: C:/Projets_EC2/GTT-2019/SUITE-ETUDE/CODE_COUPLE/code_couple_EC2/.
Set variable: PATH=.;C:\Program Files\gcc\bin;C:\Program Files\gcc\bin\bin;C:\Users\Rémi COQUARD\gcc\bin;C:\Users\Rémi COQUARD\gcc\bin\bin;C:\Program Files\gcc\libexec\gcc\x86_64-w64-mingw32\9.2.0;C:\Users\Rémi COQUARD\gcc\libexec\gcc\x86_64-w64-mingw32\8.3.0;C:\Program Files\Microsoft MPI\Bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\ComposerXE-2011\redist\intel64\mkl;C:\Program Files (x86)\Intel\ComposerXE-2011\redist\intel64\mpirt;C:\Program Files (x86)\Intel\ComposerXE-2011\compiler\lib;C:\Program Files (x86)\Intel\ComposerXE-2011\redist\intel64\compiler;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Microsoft Visual Studio\Common\TOOLS;C:\Program Files\Microsoft Visual Studio\Common\MSDEV98\BIN;C:\Program Files\Microsoft Visual Studio\DF98\BIN;C:\Program Files\Microsoft Visual Studio\VC98\BIN;C:\Program Files (x86)\Intel\Compiler\11.1\065\lib\intel64;C:\Program Files (x86)\Intel\Compiler\11.1\065\mkl\em64t\bin;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\mpirt;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\SIMULIA\Commands;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn;c:\Program Files\Microsoft SQL Server\100\Tools\Binn;c:\Program Files\Microsoft SQL Server\100\DTS\Binn;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn;C:\Program Files\Git\cmd;C:\SIMULIA\Abaqus\Commands;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\gnuplot;C:\Users\Rémi COQUARD\gcc;C:\Program Files\Docker Toolbox;C:\Users\Rémi COQUARD\AppData\Local\Microsoft\WindowsApps
Starting debugger: C:\Program Files\gcc\bin\gcc.exe -nx -fullname -quiet  -args C:/Projets_EC2/GTT-2019/SUITE-ETUDE/CODE_COUPLE/code_couple_EC2/bin/Debug/CODE-COUPLE-EXE.exe
done
Debugger finished with status 1




Without a full build log, it's difficult to help you. May be you set a wrong project : "Fortran library" instead of "Fortran application".
This could gives the message you have, because if finally you have built a library (*.a or *.dll file), it cannot be executed like that.
May be your fortran set configuration is wrong...
May be ... that's all we can say with so few informations.
« Last Edit: November 07, 2019, 03:33:34 pm by COQ »

Offline gd_on

  • Regular
  • ***
  • Posts: 488
Re: Building a Fortran project using .o module files
« Reply #8 on: November 07, 2019, 03:44:47 pm »
This is not a full build log but messages from the debugger.
Full build log is obtained in Log & other window, in Build log tags after activationg for your fortran compiler "Full commanf line" in Global compiler sttings / Compiler logging.
This is indicated tons of time in the forum, but you need to search even if you don't speak english fluently.
May be you forgot to specify the -g option at compile time. This is done automaticaaly when you build a debug project, but you can also add this option manually.

And read the wiki and the documentation (even if they are a little bit old).

gd_on
Windows 10, svn C::B (last version or almost!), WxWidgets 3.1.3, Compilers 8.1.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\MinGW64) or 32 bits (sjlj, posix in C:\MinGW32).

Offline COQ

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Building a Fortran project using .o module files
« Reply #9 on: November 07, 2019, 04:00:14 pm »
Dear gd_on,

Sorry for the amateurism ....
I send you the debug report because I thought it was due to a debugger problem

Attached is the full build log file

Thank you for your patience

Offline gd_on

  • Regular
  • ***
  • Posts: 488
Re: Building a Fortran project using .o module files
« Reply #10 on: November 07, 2019, 04:18:33 pm »
OK. -g is set.
but the debugger is gdb, not gcc which is the C compiler.
Have you gdb.exe in your distribution ? probably somewhere in a \bin folder. With some gcc distibutions, it's not included !
If you have not it, I suggest to install a 8.1.0 version, you can find in https://sourceforge.net/projects/mingw-w64/files/.
To compile in 64 bits, I suggest x86_64-posix-seh version. It's the compiler used by Codeblocks team.

I also see in your path variable that you have at least two sets of compilers installed (9.2, 8.3, and ???) :

Quote
C:\Program Files\gcc\bin;
C:\Program Files\gcc\bin\bin;
C:\Users\Rémi COQUARD\gcc\bin;
C:\Users\Rémi COQUARD\gcc\bin\bin;
C:\Program Files\gcc\libexec\gcc\x86_64-w64-mingw32\9.2.0;
C:\Users\Rémi COQUARD\gcc\libexec\gcc\x86_64-w64-mingw32\8.3.0;

It may be confusing if the path and versions within codeblocks are not correctly set.
« Last Edit: November 07, 2019, 04:33:21 pm by gd_on »
Windows 10, svn C::B (last version or almost!), WxWidgets 3.1.3, Compilers 8.1.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\MinGW64) or 32 bits (sjlj, posix in C:\MinGW32).

Offline COQ

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Building a Fortran project using .o module files
« Reply #11 on: November 07, 2019, 04:39:28 pm »
Dear,

Thank you so much. I don't know why but I actually do not specify the right debugger executable (gcc.exe instead of gdb.exe ....).

All is OK now ... I hope ....

Thank you again for your patience

Offline gd_on

  • Regular
  • ***
  • Posts: 488
Re: Building a Fortran project using .o module files
« Reply #12 on: November 07, 2019, 04:52:09 pm »
OK.
Take care also that in your paths you have your name with a é and a space. Sometimes this gives problems.
Windows 10, svn C::B (last version or almost!), WxWidgets 3.1.3, Compilers 8.1.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\MinGW64) or 32 bits (sjlj, posix in C:\MinGW32).

Offline COQ

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Building a Fortran project using .o module files
« Reply #13 on: November 08, 2019, 11:21:35 am »
Dear gd_on,

I take the liberty of recontacting you for another problem.
I have installed CodeBlocks and the gfortran compiler on another Personal Computer which actually uses Windows7 (instead of Windows10 for my PC).

The compilation of the same project is OK until I try to build the solution.
I receive the following error message :
"gfortran.exe: fatal error: -fuse-linker-plugin, but liblto_plugin-0.dll not found
compilation terminated.
"
 
Attached is the corresponding Build_Log file

Thank you again by advance

COQ

Offline gd_on

  • Regular
  • ***
  • Posts: 488
Re: Building a Fortran project using .o module files
« Reply #14 on: November 08, 2019, 12:04:55 pm »
I can't really answer.
Nevertheless, I don't think it's a Win7 / Win10 problem. It's more a problem with your gcc installation(s).
On your Win10, this dll is probably found somewhere in the Windows path, but probably not in your desired compiler path. As I told you in a previous post, I see several gcc install in your path. So, may be (once again, I can only suppose ...), this dll is in one of this install on Win10, but not on your Win7 PC.
I made a google search with liblto_plugin and found : https://stackoverflow.com/questions/11248116/using-mingw-to-compile-c-code-but-error-liblto-plugin-0-dll-not-found
But you can find other solutions.

As you told, you have only some .o (and probably also .mod) for some part of your soft. They were compiled with gfortran 8.3, from a gcc 8.3 distribution. OK. But are you sure you use exactly the same compiler from the same distribution ? I say that because some distributions are statically compiled, so no need for dll in general, and other are dynamically linked so need dlls.
So, if your .o were compiled with a dynaically linked compiler and you use a statically one, this is the problem... But, just a supposition.
An other supposition : some installers on some distributions require to set a specific environment variable (via an install.bat or update.bat ...). may be your Win7 and Win10 install have not the same environment variables ...

After looking in my own gcc install, I can find this dll. So I can suppose than on your Win7 PC, the path to this dll is wrongly configured. Why, I don't know. If you have it, try to add the folder where it is located in your Windows path (or with a -L linker setting, search path for linker).
« Last Edit: November 08, 2019, 01:19:34 pm by gd_on »
Windows 10, svn C::B (last version or almost!), WxWidgets 3.1.3, Compilers 8.1.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\MinGW64) or 32 bits (sjlj, posix in C:\MinGW32).