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

  • Context: Fortran 
  • Thread starter Thread starter Vrbic
  • Start date Start date
  • Tags Tags
    Beginner File
Click For Summary

Discussion Overview

The discussion centers around the process of creating executables from Fortran code using a makefile, particularly for a beginner using Cygwin on Windows 7. Participants explore the necessary commands and environment setup required to successfully compile and run the code, as well as the challenges faced in this process.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant expresses a lack of experience with Fortran and seeks help in producing executable files from a makefile without needing to understand all the details.
  • Another participant suggests that an executable should be generated if the environment is set up correctly and that the makefile can typically be executed using the "make" or "nmake" commands.
  • Some participants propose specific commands to run the makefile, including "make ./makefile" and "nmake ./makefile," while others clarify that the correct command is simply "make" if in the right directory.
  • A participant explains that a makefile is not a script but an input for the "make" command, which orchestrates the compilation process.
  • Concerns are raised about potential difficulties in building a large program due to missing libraries or incorrect paths, suggesting that modifications to the makefile may be necessary.
  • There is a mention of the importance of having all necessary files in one directory to simplify the build process, although this may lead to complications with conflicting file names.

Areas of Agreement / Disagreement

Participants generally agree on the necessity of using the "make" command to compile the program, but there is some confusion regarding the correct syntax and the environment setup. Multiple views on the best approach to execute the makefile and the challenges involved remain present.

Contextual Notes

Participants note that the success of the compilation process may depend on the presence of required libraries and the correct directory structure, which are not universally applicable and may vary by individual setup.

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   Reactions: 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   Reactions: Vrbic

Similar threads

  • · Replies 17 ·
Replies
17
Views
7K
  • · Replies 34 ·
2
Replies
34
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 37 ·
2
Replies
37
Views
5K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K