2

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'
    write(*,*)
    call a00aaf

end program naginfo

This is copied from the tutorial and they suggest to compile it with the following statement:

f95 -o naginfo naginfo.f90 -lnag

and they suppose that this -lnag drives the 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 the NAG files to help the linker find it.

How do I get this to compile and link?

francescalus
  • 30,576
  • 16
  • 61
  • 96
  • Which release of the library do you have? The names of the modules and library changed some time around Mark 23. – francescalus Nov 28 '16 at 19:31
  • Mark 22, from this link https://www.nag.co.uk/installing-nag-fortran-library-mark-22?ProdCode=fll3a22dfl the first item – Pak Fent L'indkio Nov 28 '16 at 19:34
  • In which case the name is probably correct, so it's probably that your module search path doesn't include the directory with the `*.mod` files. Have a look at the installation/user instructions, and the `-I` compiler flag. – francescalus Nov 28 '16 at 19:41
  • @PakFentL'indkio: I just downloaded NAG Mark 26 and had the identical problem, which landed me here where I got pointers to my (our) issue, but w/o more knowledge (eg gfortran compiler switches, etc.) remained in the dark. After returning to the documentation and samples, I found that by replacing "USE nag_f77_a_chapter" with "USE nag_library, ONLY: a00aaf" and using this command line: gfortran -I ${nagInc} nagInfo.f90 ${nagLib} -lstdc++ -o nagInfo the compilation succeeds. nagInc is ${HOME}/NAG/fll6i26dfl/nag_interface_blocks/ and nagLib is ${HOME}/NAG/fll6i26dfl/lib/libnag_nag.a – TheGeeko61 Mar 22 '18 at 05:27

1 Answers1

3

This is just a long explanation of 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. It may differ between different compilers, but is typically -I followed by the directory where the library stores its .mod files.

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

francescalus
  • 30,576
  • 16
  • 61
  • 96
  • I've tried to direct the compliler to the folder throwgh many ways, but they didn't solve the problem. Could be something related with the permisions of the archives or the instalation of the libraries? thx – Pak Fent L'indkio Nov 30 '16 at 17:45
  • @PakFentL'indkio Probably not if you can read those files. Make sure there is indeed a file `nag_f77_a_chapter.mod` in that directory. You can also try to copy them to your directory. – Vladimir F Героям слава Nov 30 '16 at 18:47