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

In summary, you are trying to build a program using make but you are not sure how to do it. You need to use the "which make" command to see if make is present. If not, you need to install make. You also need to use the "make" command to build the program.
  • #1
Vrbic
407
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
  • #2
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.
 
  • #3
Yes try the command:
Code:
make ./makefile    

--or-- 

nmake ./makefile
 
  • #4
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.
 
  • #5
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:
  • #6
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.
 
  • #7
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...?
 
  • #8
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.
 
  • #9
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

1. What is a beginner and a makefile file?

A beginner and a makefile file are two important concepts in computer programming. A beginner file, also known as a "Hello World" file, is a simple program that displays the text "Hello, World!" on the screen. This is often the first program that beginner programmers learn to write. A makefile file, on the other hand, is a script that automates the process of compiling and linking a program, making it easier to build and run the code.

2. How do I create a beginner and a makefile file?

To create a beginner file, you can use any text editor like Notepad or TextEdit to write a few lines of code that display "Hello, World!" on the screen. To create a makefile file, you will need to use a makefile generator tool or write the script manually in a text editor. The makefile should contain instructions for compiling and linking your program, as well as any additional dependencies.

3. Why are beginner and makefile files important?

Beginner and makefile files are important because they provide a foundation for learning and understanding computer programming. Beginner files help new programmers get started with writing simple code, while makefile files help streamline the process of building and running more complex programs. They also allow for easier collaboration and code maintenance.

4. Can I use a beginner and a makefile file for any programming language?

While beginner and makefile files are commonly used in languages like C and C++, they can also be used for other programming languages like Python, Java, and Ruby. However, the syntax and commands in the makefile may differ depending on the language and compiler being used.

5. Are there any alternatives to using a beginner and a makefile file?

Yes, there are alternative options for beginners and makefile files, depending on the programming language and tools being used. For beginners, there are online platforms and integrated development environments (IDEs) that provide a user-friendly interface for writing and running code. For makefile files, there are also build automation tools like CMake and Ant that can be used instead of manually writing a makefile.

Similar threads

  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
Replies
34
Views
3K
  • Programming and Computer Science
2
Replies
37
Views
3K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
1
Views
758
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
9
Views
3K
  • Programming and Computer Science
Replies
4
Views
607
Back
Top