Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to compile multi-folder Fortran Project having interfaces, modules and subroutines
    primarykey
    data
    text
    <p>I am new to Fortran. I am working on a research project where I am using an open source project that has several files distributed in multiple folders. i found the dependency of each programs but could not figure out how to compile them.</p> <p>I have source code distributed in three folders. a)modules b)interfaces c)subroutines</p> <p>I would like to run a program named as 'Main.f90' in subroutines folder, this program has dependency of source codes from modules and interfaces folders.</p> <p>I am using eclipse for folder structure and makefile to compile.</p> <p>Any help with this is appreciated.</p> <p><strong>UPDATE:</strong> I followed the answer posted by @MBR and @Stefan, for some reason VPATH did not able to find programs in source code so I explicitly gave path to those source folder in my <em>Makefile</em>. below is my make file script.</p> <pre><code> .PHONY: Mopac_exe clean # Change this line if you are using a different Fortran compiler FORTRAN_COMPILER = gfortran SRC = src #make main program Mopac_exe: subroutines mopac.o $(FORTRAN_COMPILER) mopac.o *.o -O2 -g -o bin/Mopac_exe -I Modules/ #compile all the subroutines subroutines: interfaces $(FORTRAN_COMPILER) -c $(SRC)/subroutines/*.F90 -J Modules/Subroutines/ -I Modules/ #compiles all the interfaces interfaces: modules $(FORTRAN_COMPILER) -c $(SRC)/interfaces/*.f90 -J Modules/ # build all the modules and generate .mod file in Modules directory modules: build_vast_kind $(FORTRAN_COMPILER) -c $(SRC)/modules/*.f90 -J Modules/ $(FORTRAN_COMPILER) -c $(SRC)/modules/*.F90 -J Modules/ # compile vastkind.f90 files and generates the .mod file in Modules directory.Every other Modules and interfaces are dependent on this. build_vast_kind:clean $(FORTRAN_COMPILER) -c $(SRC)/modules/vastkind.f90 -J Modules/ clean: rm -f bin/Mopac_exe *.mod rm -f Modules/*.mod rm -f *.o </code></pre> <p>I compiled all the modules and placed in Modules directory of root Folder. All compilation goes well. I get error when I build the executable. I get following error. </p> <pre><code> gfortran mopac.o *.o -O2 -g -o bin/Mopac_exe -I Modules/ mopac.o: In function `main': mopac.F90:(.text+0x27c1): multiple definition of `main' mopac.o:mopac.F90:(.text+0x27c1): first defined here getdat.o: In function `getdat_': getdat.F90:(.text+0x22): undefined reference to `iargc_' getdat.F90:(.text+0xf2): undefined reference to `getarg_' symr.o: In function `symr_': symr.F90:(.text+0xd3f): undefined reference to `symp_' writmo.o: In function `writmo_': writmo.F90:(.text+0x20c2): undefined reference to `volume_' collect2: error: ld returned 1 exit status make: *** [Mopac_exe] Error 1 </code></pre> <p>`iargc_' is being used in 'getdat file and iargc is already compiled. why there is error while making the executable saying undefined reference? what am I missing?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload