Problem with running multiple projects on CODE::BLOCKS + Fortran compiler

77 views
Skip to first unread message

Doujinium De L'Exupère

unread,
Jan 18, 2021, 11:18:38 PM1/18/21
to CBFortran
Hello folks,

I'm trying to run a bunch of f.90 files in order on Code:Blocks.
I created a project for each set of files to ensure it is compiled in order.
But when I try to compile the projects, or just the first one, I get the following message:


-------------- Build: Debug in Runthisfirst (compiler: GNU Fortran Compiler)---------------

mingw32-gfortran.exe  -o bin\Debug\Program_v2.exe obj\Debug\program_v2\src\runthisfirst\runthisfirst.o   
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status

Any help would much appreciated.

D.
 

Darius Markauskas

unread,
Jan 19, 2021, 6:06:55 AM1/19/21
to cbfo...@googlegroups.com
Hello,

I can't be sure, but I think you try to compile to *.exe (program). However, your project has no 'Program' in the code. Add 'Program' or change the project type from 'Console application' to 'Static library' or 'Dynamic library' in menu Project->Properties.

I would guess that you like to get just one program at the end. Set just one project with Program to 'Console application', while others to 'Static library'.

--
You received this message because you are subscribed to the Google Groups "CBFortran" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cbfortran+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cbfortran/feeb2456-8ee5-4842-a2fa-ef784cf4ce46n%40googlegroups.com.

Doujinium De L'Exupère

unread,
Jan 19, 2021, 9:11:11 AM1/19/21
to CBFortran
Hello Darius,

I can't be sure, but I think you try to compile to *.exe (program). However, your project has no 'Program' in the code. Add 'Program'
Indeed, I need all the files to come together in a .exe by the end, which wasn't a problem on Linux but is my main challenge so far on Windows.
I do need my Fortran code to be modifiable and executable on Windows though.
How would you add 'Program' in the code? I looked up the available options on Code Blocks to create a project or an entity and there isn't one
 
or change the project type from 'Console application' to 'Static library' or 'Dynamic library' in menu Project->Properties.
I conducted this change to the first file I run.
Then I left the second one, which calls the first one, as a console application. 
But whenever I run the second one, it stops at the line of code calling the first file and gives me the message no such file or directory.
I tried building and compiling the library but it didn't work either.
Am I missing something?


I would guess that you like to get just one program at the end. Set just one project with Program to 'Console application', while others to 'Static library'.
my code works in sort of a Russian dolls paradigm. So if I understand you correctly, do I define every bigger doll as a library until I reach my main program interface and THEN make that final file my console application?   

Thanks you thank you,

Darius Markauskas

unread,
Jan 19, 2021, 11:27:24 AM1/19/21
to cbfo...@googlegroups.com
"""How would you add 'Program' in the code?"""
By 'Program' I mean Fortran 'program' statement ('main' function if you come from C++).

"""
Then I left the second one, which calls the first one, as a console application. 
But whenever I run the second one, it stops at the line of code calling the first file and gives me the message no such file or directory.
I tried building and compiling the library but it didn't work either.
Am I missing something?
"""
You should ensure that dependencies are found during the linking step. Dependencies should be added in the project build options dialog.

"""my code works in sort of a Russian dolls paradigm. """

Nice comparison ;)

"""
So if I understand you correctly, do I define every bigger doll as a library until I reach my main program interface and THEN make that final file my console application? 
"""
Yes. This concept is not specific to C::B or Fortran. The same is for other compiled languages.

If you are new to 'static library', 'linking', 'dependencies between libraries', then I would suggest you start from the simpler case: Just make one 'Console application' project and add all your files to it. Ensure you have just one 'Program' statement in your Fortran code. And compile the code in C::B. C::B can handle quite big project files without problems.

Doujinium De L'Exupère

unread,
Jan 20, 2021, 9:38:21 AM1/20/21
to CBFortran
By 'Program' I mean Fortran 'program' statement ('main' function if you come from C++).

I actually have one Fortran program statement on the main file that calls my other modules.
 
You should ensure that dependencies are found during the linking step. Dependencies should be added in the project build options dialog.

That one was a tough Darius. I have been scouring the internet for two days with no answer as to how I can create library files out of my subroutines and modules. I did introduce them as fortran libraries in my workspace but they don't display as potential files in my linking options and don't have the right extension anyway
 

If you are new to 'static library', 'linking', 'dependencies between libraries', then I would suggest you start from the simpler case: Just make one 'Console application' project and add all your files to it. Ensure you have just one 'Program' statement in your Fortran code. And compile the code in C::B. C::B can handle quite big project files without problems.

Actually, that was my first instinct. I created one project to which I added all my files, tried building it and got errors; the kinds I defined in one file weren't recognized throughout the rest of the files, eventhough they are cited as occurences when I check. 
I also had the file containing the kinds with the highest priority for building but it didn't matter.

Darius Markauskas

unread,
Jan 20, 2021, 10:39:04 AM1/20/21
to cbfo...@googlegroups.com
"""Actually, that was my first instinct. I created one project to which I added all my files, tried building it and got errors; the kinds I defined in one file weren't recognized throughout the rest of the files, eventhough they are cited as occurences when I check. 
I also had the file containing the kinds with the highest priority for building but it didn't matter."""

If you like, you can post some screenshots with error messages. You can use my email if you prefer. I can help you, perhaps.



Reply all
Reply to author
Forward
0 new messages