Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
97 Views

How to compile and link a many source file program efficiently from the command line

Hi,

I have a program consisting of a number of hundreds of subroutines residing in the same folder. How do I write the ifort command to compile and link these subroutines?  I guess a batchfile will be needed if all subroutines have to be listed. If so, can I retrieve the subroutines names from VS, which I have used until now?

Best regards

Anders S

0 Kudos
7 Replies
Highlighted
Black Belt
97 Views

How many files are there? The number of subroutines is not relevant.

You can get a list of the files in a directory using command line tools such as dir.

dir *.f90 /b > some_file.txt

You can then edit and change the order of the file names in that file.  Changing the order might be necessary if your source code contains modules.

You can then pass this list of files to ifort:

ifort @some_file.txt

Add appropriate compiler command line options to suit. The option that enables parallel compilation ('/MP', if memory serves me correctly) mzy be of interest if you have lots of files.

Note you can invoke the build system used by Visual Studio from the command line too.

For routine development of a program using a command line you would normally use some sort of build tool, of which there are many.

0 Kudos
Highlighted
97 Views

Normally a programmer would us a make file (NMAKE under Windows) for this.

https://msdn.microsoft.com/en-us/library/dd9y37ha.aspx
http://www.lahey.com/docs/lfprohelp/F95UGMUNMAKEBmult.htm
http://www.lahey.com/docs/lfprohelp/F95UGMUNMAKEBlib.htm
http://www.lahey.com/docs/lfprohelp/F95UGMUNMAKEBmod.htm

If you are not using modules, the second link may be of interest.

Jim Dempsey

 

0 Kudos
Highlighted
New Contributor III
97 Views

Hi Anders,

I like to setup a makefile if there are several source files, instead of a batch file, to avoid rebuilding the entire project when there are changes to just a few source files. In addition to the links Jim provided, there is an example of a Windows makefile to run using "nmake" in this previous forum article:

https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux-and-mac-os-x/topic/673617

Regards, Greg

0 Kudos
Highlighted
Beginner
97 Views

Hi IanH,

Thanks for you quick reply, which gives a simple but easy way to compile and link my program! Will I get in trouble if the text file contains more subroutine names than needed to produce an exe module. This situation appears when you are trouble-shooting and take away some subroutine call in the code.

Best regards

Anders S

0 Kudos
Highlighted
Beginner
97 Views

Hi Greg and Jim,

Thanks for your advice! I have been using VS up till now, when MPI came into the picture requiring command line (CL) work. At the moment I use both VS and CL. Is it so that makefile requires less work to implement as I am already using VS? In any case, makefile or nmake is the next step if I go for the CL alternative in the future.

Best regards

Anders S 

0 Kudos
Highlighted
New Contributor II
97 Views

The text file contains a list of file names, not subroutine names.  Each file will contain Fortran code, possibly many subroutines and functions.  It is not a problem to include subroutines that are never called in the program, but of course all subroutines that are called must be present.

0 Kudos
Highlighted
Black Belt
97 Views

In this context, it is good to be aware of a number of utilities that can be used to scan a set of Fortran sources from which an EXE or DLL is to be built, and generate a makefile that takes into account the module dependencies and builds the objects in the proper order. Follow the "makefile builders" links on the page http://www.fortran.com/the-fortran-company-homepage/fortran-tools-libraries-and-application-software/ , and Polyhedron Software's AutoMake, https://www.polyhedron.com/Automake7 .

0 Kudos