Fortran 90 AND shared libraries.
I created a shared library with my most used mathematical functions using fortran 90. I intended to make my life easier, since I thought I could call the shared functions as simple as I call an intrinsic function like sin(x) or cos(x). However, I noted the functions in the shared library are treated as EXTERNAL functions. At this point my life became hard, because I have to interface my shared functions all the time. Is there a way to overcome this problem using fortran 90? Does this problem appear when using fortran 95?
|
Using Fortran 90/95 you can either write a library using module interfaces or just simple functions. I think it all depends on how did you wrote the function library and how did you compile/link it. Consider the following (very simplified) example. I am using the Intel fortran compiler on this machine:
Code:
$ ls |
Ok, I realized. But, suppose instead of my_sum.f90 I have a function
getsize(X) in a separated file: Code:
function getsize(X) Code:
program main You said it is possible write a library using module interfaces. I tried to do that, but it did not work. Suppose instead of the code above I have (in a separated file) Code:
module mysize Code:
program main Thanks a lot! Quote:
|
Your last example works for me. Here is an excerpt from Stephen Chapman's "FORTRAN 95/2003 for scientist and engineers" (don't waste time to look for it in the web... I have the book) ;)
Quote:
Code:
$ cat mysize.f90 |
Hi colucix!
Perhaps the program worked because the mysize.mod and mysize.o files were in the directory. Try to remove them before using the command Code:
ifort -L. main.f90 -ltest Code:
hoggar%~/fortran/code ls Thank you! Quote:
|
It works for me. But...
1) you have to preserve the mysize.mod and put it in some Include path, since it is used during the compilation of the main program 2) you have to tell to the system where to find the shared library, that is change the LD_LIBRARY_PATH environment variable accordingly OR use ldconfig to add the directory containing the libraries to the cache of the shared objects. This equals to provide a devel package, that is: if you want to share with others the newly created libraries you have to provide both the libs and the includes. The library will be enough for already compiled executables linking against it. In addition the .mod will be necessary to develop and compile new applications! I try again, just to be sure: Code:
$ pwd |
All times are GMT -5. The time now is 06:23 AM. |