Pak Fent L'indkio Pak Fent L'indkio - 4 days ago 6
Linux Question

Link to NAG library with -lnag

I'm trying to compile my first program which uses the NAG library, the following:

program naginfo

use nag_f77_a_chapter
implicit none

write(*,*) 'Calling NAG identification routine'
call a00aaf

end program naginfo

copied from the tutorial, then they suggest me to compile it with the following statement:

f95 -o naginfo naginfo.f90 -lnag

and they suppose that this
drives de linker to NAG library, but then I find this error:

Fatal Error: Can't open module file ‘nag_f77_a_chapter.mod’ for reading at (1): The directory does not exist

I've tried changing the directory of NAG files to help the linker to find it. I don't know so much about programming, so I think that's a stupid solution. Do you know what may be happening in there?


This is just a long explanation of the francescalus's comment.

The flag -lnag only adds the library code to the already compiled program when linking all compiled pieces together. It has no effect during compilation and hence no effect on the error message you see.

The compiler must see the information about the NAG library modules. That is usually stored in module files with the .mod extension. Compilers normally only search for these in the current directory or in the system's include directories.

You can instruct the compiler to search in a different directory by using a special compiler flag. that may differ between different compilers, but is typically -I followed by the directory where the library stores its .mod files.

Be adviced that the .mod files in the library are only compatible with the same compiler that was used to create them by the library vendor.