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

Subroutine problem

royxu
Beginner
768 Views
I have some problems to call external subroutine by using Fortran Compiler in Linux. My program was orginially tested in Windows where I have the NAG library support.When I migrated it to Linux, I don't have the NAG library support. But I have all source codes for the subroutines I am going to use in my program, such as G05CBF, D01AHF, etc.
My question is how do I call these external subroutine using my program in Linux. Do I have to integrate my program with all external subroutines into one big program?
Thanks!
Roy
0 Kudos
5 Replies
TimP
Honored Contributor III
768 Views
You could make the .o files separately, or in groups of your choosing. Then use ar (standard linux tool) to make libraries, if you like. You would need to build everything together in an integrated way only if you wish to test full interprocedural optimization, which is not likely to be relevant.
0 Kudos
royxu
Beginner
768 Views
I am not quite sure about the procedure. Do you mean I need to compile each subroutine (G05CBF, C05ADF, etc) and generate each .o file? Then I need to use "ar" in Linux to put all .o files into the new library XXX. After that I can use "USE XXX" statement in my program to call this library, right?
Thanks!
0 Kudos
Steven_L_Intel1
Employee
768 Views
The Fortran USE statement has nothing to do with libraries. It is for Fortran modules.

If you use ar to build a .a file, then you simply name the .a file in your ifort command that builds the executable as if it were a source file. For exsample:

ifort -o myprog myprog.f90 mathlib.a
0 Kudos
royxu
Beginner
768 Views

Thank you for your explanation. I am clear about how to call the library in Linux.

I still have some problems when I build my library. For example, my program is going to use G05CBF subroutine. So I found the source codes for all subroutines which will be called in G05CBF. They arethree more, g05cay.f, g05caz.f andx02ajf.f. Then I compiled them by using:

ifort -o g05cbf g05cbf.f g05cay.f g05caz.f x02ajf.f

I hope I can get g05cbf.o. Then I can do the same things for other subroutines used in my program. My goal is to put all .o files into library.

However I got the following error message:

/opt/intel/fc/9.0/lib/for_main.o(.text+0x41): In function `main':
: undefined reference to `MAIN__'

There is no MAIN function in each subroutine. How can I compile them? Any suggestion on building my own library for some specific subroutines?

Thanks!

Roy

0 Kudos
Steven_L_Intel1
Employee
768 Views
Add the -c switch for compile-only.
0 Kudos
Reply