Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29273 Discussions

How to use modules and objects that are in another directory?

gittenlucky
Beginner
3,571 Views

I am looking to access subroutines that are in another directory, but I can't figure out how to note what directory they are in when I am compiling my code. I am trying to just do a "hello world" example, so I can modify it for my more complex code.

Here is the folder setup I am trying for.

/user/myname/common_files/numerical_recipes/

.../imsl/

.../custom_routines/

/user/myname/program_A/

/user/myname/program_B/

I want to be able to access common subroutines/modules/*.o files that I have stored and compiled in the first three directories from programs I have in other directories.

I have used the > ifort -c programA.f90 -I/dir/ to point the compiler to where the module is, and that works fine, but when I am trying to compile the entire thing, I don't know how to point it to the object files.

Here is my makefile...

[bash]exectutable_program_a:  program_A.o

	ifort -o executable_program_a program_A.o

program_A.o: program_A.f90

	ifort -c program_A.f90 -I/path/to/subroutines/module[/bash]

I am getting an error that the object file for the subroutine file can not be located. Any help would be greatly appreciated!

0 Kudos
1 Solution
Kevin_D_Intel
Employee
3,571 Views

As you noted, the compiler accesses module files via the -I option, but the linker's (ld), invoked via ifort, access to routines defined in modules is done by providing the path to .o files relative to make's working directory upon reaching the link rule (e.g. executable_program_a: ). It appears from the rules show the working directory for program_A will be: /user/myname/program_A.

For program_A to resolve references to subroutines defined in modules from your first three directories, you must provide the linker a path to those object files and so your rule becomes something like:

executable_program_a: program_A.o

ifort -o executable_program_a ../common_files/numerical_recipes/*.o ../common_files/imsl/*.o ../common_files/custom_routines/*.o program_A.o

View solution in original post

0 Kudos
2 Replies
Kevin_D_Intel
Employee
3,572 Views

As you noted, the compiler accesses module files via the -I option, but the linker's (ld), invoked via ifort, access to routines defined in modules is done by providing the path to .o files relative to make's working directory upon reaching the link rule (e.g. executable_program_a: ). It appears from the rules show the working directory for program_A will be: /user/myname/program_A.

For program_A to resolve references to subroutines defined in modules from your first three directories, you must provide the linker a path to those object files and so your rule becomes something like:

executable_program_a: program_A.o

ifort -o executable_program_a ../common_files/numerical_recipes/*.o ../common_files/imsl/*.o ../common_files/custom_routines/*.o program_A.o

0 Kudos
gittenlucky
Beginner
3,571 Views
That was exactly what I was looking for. Thank you very much.
0 Kudos
Reply