Fortran Creating Executables from Fortran Code Using Makefile: A Beginner's Guide

  • Thread starter Thread starter Vrbic
  • Start date Start date
  • Tags Tags
    Beginner File
AI Thread Summary
A young physicist is seeking assistance with compiling a Fortran program using Cygwin on Windows 7. They have a large codebase and need to produce tables from it but are unsure how to create an executable from the provided makefile. Initial attempts to run the makefile directly resulted in errors, leading to confusion about the correct commands to use. It is clarified that a makefile is not executable by itself; instead, it is an input for the "make" command, which compiles the program based on the instructions within the makefile. The correct command to run is simply "make," provided the user is in the directory containing the makefile and all necessary files. If issues persist, it may be necessary to check for the presence of required libraries and adjust the makefile accordingly.
Vrbic
Messages
400
Reaction score
18
Hello,
I'm young physicist and I have had a first contact with program in fortran. It is not my code but I have got an assignment to use that for my purpose. I can program in C. I watched few videos lessons for beginers about fortran and I hope I understand a structure and common commands. Now I have big code to produce some tables which are important for me. In folder are sources *.f some tables *.atb and makefile *.
I'm using windows 7 and cygwin terminal for that purpose. I mostly understand the commands but I don't have any idea how to produce executable file from makefile or something help me to produce my desire tables.
Maybe it may seems stupide but for me isn't important understand all, just produce table from that code, if it is possible without deep studing. If not I will study.

I tried to run a makefile in this terminal (I guess it is same as in linux)
"./makefile" and result was that any uncommented line was an error.

Thanks for a help, an advice, anythink.
 
Technology news on Phys.org
Are you working in an environment where you have compiled and built your program? If so, there should be an executable .exe file that you can run within that environment or from the command line. That environment will probably use a makefile or some other equivalent, but you probably don't have to know about them till you are more experienced.

Makefiles can usually be executed directly with the "make" of "nmake" command.
 
Yes try the command:
Code:
make ./makefile    

--or-- 

nmake ./makefile
 
FactChecker said:
Are you working in an environment where you have compiled and built your program? If so, there should be an executable .exe file that you can run within that environment or from the command line. That environment will probably use a makefile or some other equivalent, but you probably don't have to know about them till you are more experienced.
I didn't write this code. My attempts of fortran code (as "Hello world" but also more complex) were written in text editor and comapiled in linux environment cygwin ( https://en.wikipedia.org/wiki/Cygwin ) using command gfortran "*.* -o filename". Now I don't know how in this cygwin run a makefile.
 
It says "make in the wikipedia article is part of MinGW:

Alternative Windows/Unix integration tools
Several open-source and proprietary alternatives provide simultaneous access to both Windows and UNIX environments on the same hardware.

Toolsets like Windows Subsystem for Linux, Microsoft Windows Services for UNIX (SFU), UWIN, MKS Toolkit for Enterprise Developers and Hamilton C shell also aim to provide a Unix-like user- and development-environment. They implement at least a shell and a set of the most popular utilities. Most include the familiar GNU and/or Unix development tools, including make, yacc, lex and a https://en.wikipedia.org/w/index.php?title=Cc_(software)&action=edit&redlink=1 command which acts a wrapper around a supported C compiler. SFU also includes the GCC compiler.

https://en.wikipedia.org/wiki/Cygwin

try using the "which" command to see if make is present: "which make"
 
Last edited:
jedishrfu said:
Yes try the command:
Code:
make ./makefile   

--or--

nmake ./makefile
I tried that but for both command not found if I do only ./makefile it runs but every line is command not found.
 
jedishrfu said:
It says "make in the wikipedia article is part of MinGW:
try using the "which" command to see if make is present: "which make"
Now I don't understand...the link is wrong or...?
 
Vrbic said:
I tried that but for both command not found if I do only ./makefile it runs but every line is command not found.

A makefile is not a runnable script, its an input to the "make" command explaining to make how to build your program, what source files to compile, what libraries are needed and how to link everything together. Basically make runs other commands like gfortran... to build your executable file.
 
Trying to build a large program on a new machine can be difficult even with a makefile. The program is likely to need many libraries that are in different places or not even on your machine. In that case, the makefile would need to be changed and libraries may need to be installed.
 
  • #10
As usual a fortune helps. The desired command is (only) "make", if you are in folder where is everything needed.
Thank you all.
 
  • #11
jedishrfu said:
Yes try the command:
Code:
make ./makefile   

--or--

nmake ./makefile
You mean
Code:
make -f ./makefile
 
  • Like
Likes jedishrfu
  • #12
DrClaude said:
You mean
Code:
make -f ./makefile
In my case is right command:
Code:
make
If and only if you are in folder where are all included files and file makefile.
 
  • #13
Usually the makefile, directory structure, and locations of libraries make this much more complicated. But if putting everything in one directory works, that is excellent. That is often prevented by conflicting file names that would need to be changed along with any associated "include" statements.
 
  • Like
Likes Vrbic

Similar threads

Replies
17
Views
6K
Replies
34
Views
4K
Replies
9
Views
3K
Replies
5
Views
5K
Replies
4
Views
2K
Replies
4
Views
2K
Replies
8
Views
4K
Back
Top