- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
actually I'm trying to compile a program that uses a module mod1 consisting of many submodules. Those submodules are using by themself functions from an other module mod2 that consists of module procedures (all in a single file, but using the same logic as submodules). My makefile looks something like (I'm using ifort 16.0):
... #DIRECTORY OF MOD2 INC=-I./mod2_dir #SUBMODULES OF MOD1 MOD1_SMOD = $(shell find mod1_*.f90) all: program #COMPILE MODULE MOD1 mod1.o: mod1.f90 ./mod2_dir/mod2.o $(FC) $(CO) -c $^ $(LIBS) $(INC) #COMPILE SUBMODULES OF MOD1 $(MOD1_SMOD:.f90=.o): $(MOD1_SMOD) mod1.o $(FC) $(CO) -c $^ $(LIBS) $(INC) #COMPILE MODULE MOD2 ./mod2_dir/mod2.o: cd ./mod2_dir/; make #COMPILE AND LINK PROGRAM program: program.f90 $(MOD1_SMOD:.f90=.o) mod1.o ./mod2_dir/mod2.o $(FC) $(CO) -o $@ $^ $(LIBS) $(INC) ...
When linking the program I'm getting errors of undefined references to the module procedure functions of mod2.f90 that are called from submodules (MOD1_SMOD) of mod1 (like `mod2_MP_mod2_fooxy_'). Can anybody tell me where my fallacy is?
Also, I don't understand why I have to explictly state all submodule object files, since for each sobmodule exists a *,smod file within the search directories. Shouldn't they be found automatically??
I would be very grateful for any advice!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
zp3 wrote:
I don't understand why I have to explictly state all submodule object files, since for each submodule exists a *.smod file within the search directories. Shouldn't they be found automatically?
The compiler uses/produces module files when it is asked to compile Fortran source files into object files. The linker has no contact with module files; it processes only object files, library files and export files.
With regard to your other question (about undefined externals at link time), I don't wish to speculate based on only the makefile and your description. It would help if you showed us the source codes, at least in skeleton form, or told us about the USE statements in your sources.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
mecej4 wrote:
The compiler uses/produces module files when it is asked to compile Fortran source files into object files. The linker has no contact with module files; it processes only object files, library files and export files.
When I'm using for example:
program: program.f90 $(MOD1_SMOD:.f90=.o) mod1.o ./mod2_dir/mod2.o $(FC) $(CO) -o $@ program.f90 $(LIBS) $(INC)
instead of:
program: program.f90 $(MOD1_SMOD:.f90=.o) mod1.o ./mod2_dir/mod2.o $(FC) $(CO) -o $@ $^ $(LIBS) $(INC)
the compiler automatically finds the mod1.o module file but does not find the mod1_*.o submodule files (when using the -I command).
mecej4 wrote:
With regard to your other question (about undefined externals at link time), I don't wish to speculate based on only the makefile and your description. It would help if you showed us the source codes, at least in skeleton form, or told us about the USE statements in your sources.
The whole source code is quite complicated and probably not easy to understand and imo wouldn't help to get the problem. When compiling all source files in a single folder/command it works. For the USEs: program.f90 uses only module mod1; (sub)module procedures of module mod1 are using only itself and the module mod2; mod2 uses only other stuff.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have you used MAKE wildcards?
Jim Dempsey

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page