0

I am having some trouble compiling my Fortran code with lapack using CMake - I am new to all of this. I have blas and lapack installed in /usr/lib/x86_64-linux-gnu/ and am using the following CMakeLists.txt file:

cmake_minimum_required(VERSION 3.27)
project(DVR Fortran)

enable_language(Fortran)


set(BLAS_DIR "/usr/lib/x86_64-linux-gnu/blas")
set(LAPACK_DIR "/usr/lib/x86_64-linux-gnu/lapack")
find_package(LAPACK REQUIRED)
if(LAPACK_FOUND AND BLAS_FOUND)
    set(LAPACKBLAS_LIBRARIES ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
    message("BLAS FOUND: " ${BLAS_LIBRARIES})
    message("LAPACK FOUND: " ${LAPACK_LIBRARIES})
endif()
include_directories(${LAPACK_INCLUDE_DIRS})
include_directories(${BLAS_INCLUDE_DIRS})


set(SOURCES
        types.f90
        io.f90
        grid_gen.f90
        potentials.f90
        dvr_solvers.f90
        main.f90
)

add_executable(dvr ${SOURCES})
target_compile_options(dvr PRIVATE -llapack)
target_link_libraries(dvr ${LAPACKBLAS_LIBRARIES})

which compiles fine (with f95) and prints that the blas and lapack libraries are found. Note I am using CLion as an IDE and am building my project within that. However, as soon as I add use lapack or use lapack95 to main.f90 - I get an error saying it can't find lapack.mod. I was previously using gfortran and when I set the compiler to gfortran in CMakelists.txt I do not get any errors however it does not print that blas and lapack are found as it should according to the if block in CMakelists.txt. I have been stuck with this for a while and am confused as to why whatever compiler I use with -llapack flag does not seem to generate the .mod files, how can I be sure they are generated and use the lapack functions in main.f90 or any of my other modules? Any help would be appreciated.

Thanks.

UPDATE:

output of build without use lapack in main.f90:

opt/clion-2023.3.2/bin/cmake/linux/x64/bin/cmake --build /home/usrkm/CLionProjects/DVR/cmake-build-debug --target dvr -j 18 -v
Change Dir: '/home/usrkm/CLionProjects/DVR/cmake-build-debug'

Run Build Command(s): /opt/clion-2023.3.2/bin/ninja/linux/x64/ninja -v -j 18 dvr
[0/1] /opt/clion-2023.3.2/bin/cmake/linux/x64/bin/cmake --regenerate-during-build -S/home/usrkm/CLionProjects/DVR -B/home/usrkm/CLionProjects/DVR/cmake-build-debug
BLAS FOUND: /usr/lib/x86_64-linux-gnu/libblas.so
LAPACK FOUND: /usr/lib/x86_64-linux-gnu/liblapack.so/usr/lib/x86_64-linux-gnu/libblas.so
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: /home/usrkm/CLionProjects/DVR/cmake-build-debug
[1/14] gfortran -cpp   -g -fdiagnostics-color=always -llapack -E /home/usrkm/CLionProjects/DVR/grid_gen.f90 -o CMakeFiles/dvr.dir/grid_gen.f90-pp.f90 && /opt/clion-2023.3.2/bin/cmake/linux/x64/bin/cmake -E cmake_ninja_depends --tdi=CMakeFiles/dvr.dir/FortranDependInfo.json --lang=Fortran --src=CMakeFiles/dvr.dir/grid_gen.f90-pp.f90 --out=CMakeFiles/dvr.dir/grid_gen.f90-pp.f90 --dep=CMakeFiles/dvr.dir/grid_gen.f90-pp.f90.d --obj=CMakeFiles/dvr.dir/grid_gen.f90.o --ddi=CMakeFiles/dvr.dir/grid_gen.f90.o.ddi
[2/14] gfortran -cpp   -g -fdiagnostics-color=always -llapack -E /home/usrkm/CLionProjects/DVR/types.f90 -o CMakeFiles/dvr.dir/types.f90-pp.f90 && /opt/clion-2023.3.2/bin/cmake/linux/x64/bin/cmake -E cmake_ninja_depends --tdi=CMakeFiles/dvr.dir/FortranDependInfo.json --lang=Fortran --src=CMakeFiles/dvr.dir/types.f90-pp.f90 --out=CMakeFiles/dvr.dir/types.f90-pp.f90 --dep=CMakeFiles/dvr.dir/types.f90-pp.f90.d --obj=CMakeFiles/dvr.dir/types.f90.o --ddi=CMakeFiles/dvr.dir/types.f90.o.ddi
[3/14] gfortran -cpp   -g -fdiagnostics-color=always -llapack -E /home/usrkm/CLionProjects/DVR/io.f90 -o CMakeFiles/dvr.dir/io.f90-pp.f90 && /opt/clion-2023.3.2/bin/cmake/linux/x64/bin/cmake -E cmake_ninja_depends --tdi=CMakeFiles/dvr.dir/FortranDependInfo.json --lang=Fortran --src=CMakeFiles/dvr.dir/io.f90-pp.f90 --out=CMakeFiles/dvr.dir/io.f90-pp.f90 --dep=CMakeFiles/dvr.dir/io.f90-pp.f90.d --obj=CMakeFiles/dvr.dir/io.f90.o --ddi=CMakeFiles/dvr.dir/io.f90.o.ddi
[4/14] gfortran -cpp   -g -fdiagnostics-color=always -llapack -E /home/usrkm/CLionProjects/DVR/potentials.f90 -o CMakeFiles/dvr.dir/potentials.f90-pp.f90 && /opt/clion-2023.3.2/bin/cmake/linux/x64/bin/cmake -E cmake_ninja_depends --tdi=CMakeFiles/dvr.dir/FortranDependInfo.json --lang=Fortran --src=CMakeFiles/dvr.dir/potentials.f90-pp.f90 --out=CMakeFiles/dvr.dir/potentials.f90-pp.f90 --dep=CMakeFiles/dvr.dir/potentials.f90-pp.f90.d --obj=CMakeFiles/dvr.dir/potentials.f90.o --ddi=CMakeFiles/dvr.dir/potentials.f90.o.ddi
[5/14] gfortran -cpp   -g -fdiagnostics-color=always -llapack -E /home/usrkm/CLionProjects/DVR/dvr_solvers.f90 -o CMakeFiles/dvr.dir/dvr_solvers.f90-pp.f90 && /opt/clion-2023.3.2/bin/cmake/linux/x64/bin/cmake -E cmake_ninja_depends --tdi=CMakeFiles/dvr.dir/FortranDependInfo.json --lang=Fortran --src=CMakeFiles/dvr.dir/dvr_solvers.f90-pp.f90 --out=CMakeFiles/dvr.dir/dvr_solvers.f90-pp.f90 --dep=CMakeFiles/dvr.dir/dvr_solvers.f90-pp.f90.d --obj=CMakeFiles/dvr.dir/dvr_solvers.f90.o --ddi=CMakeFiles/dvr.dir/dvr_solvers.f90.o.ddi
[6/14] gfortran -cpp   -g -fdiagnostics-color=always -llapack -E /home/usrkm/CLionProjects/DVR/main.f90 -o CMakeFiles/dvr.dir/main.f90-pp.f90 && /opt/clion-2023.3.2/bin/cmake/linux/x64/bin/cmake -E cmake_ninja_depends --tdi=CMakeFiles/dvr.dir/FortranDependInfo.json --lang=Fortran --src=CMakeFiles/dvr.dir/main.f90-pp.f90 --out=CMakeFiles/dvr.dir/main.f90-pp.f90 --dep=CMakeFiles/dvr.dir/main.f90-pp.f90.d --obj=CMakeFiles/dvr.dir/main.f90.o --ddi=CMakeFiles/dvr.dir/main.f90.o.ddi
[7/14] /opt/clion-2023.3.2/bin/cmake/linux/x64/bin/cmake -E cmake_ninja_dyndep --tdi=CMakeFiles/dvr.dir/FortranDependInfo.json --lang=Fortran --dd=CMakeFiles/dvr.dir/Fortran.dd @CMakeFiles/dvr.dir/Fortran.dd.rsp
[8/14] gfortran -I/home/usrkm/CLionProjects/DVR -g -fdiagnostics-color=always -llapack -fpreprocessed -c CMakeFiles/dvr.dir/types.f90-pp.f90 -o CMakeFiles/dvr.dir/types.f90.o
[9/14] gfortran -I/home/usrkm/CLionProjects/DVR -g -fdiagnostics-color=always -llapack -fpreprocessed -c CMakeFiles/dvr.dir/grid_gen.f90-pp.f90 -o CMakeFiles/dvr.dir/grid_gen.f90.o
[10/14] gfortran -I/home/usrkm/CLionProjects/DVR -g -fdiagnostics-color=always -llapack -fpreprocessed -c CMakeFiles/dvr.dir/io.f90-pp.f90 -o CMakeFiles/dvr.dir/io.f90.o
[11/14] gfortran -I/home/usrkm/CLionProjects/DVR -g -fdiagnostics-color=always -llapack -fpreprocessed -c CMakeFiles/dvr.dir/potentials.f90-pp.f90 -o CMakeFiles/dvr.dir/potentials.f90.o
[12/14] gfortran -I/home/usrkm/CLionProjects/DVR -g -fdiagnostics-color=always -llapack -fpreprocessed -c CMakeFiles/dvr.dir/dvr_solvers.f90-pp.f90 -o CMakeFiles/dvr.dir/dvr_solvers.f90.o
[13/14] gfortran -I/home/usrkm/CLionProjects/DVR -g -fdiagnostics-color=always -llapack -fpreprocessed -c CMakeFiles/dvr.dir/main.f90-pp.f90 -o CMakeFiles/dvr.dir/main.f90.o
[14/14] : && gfortran  -g CMakeFiles/dvr.dir/types.f90.o CMakeFiles/dvr.dir/io.f90.o CMakeFiles/dvr.dir/grid_gen.f90.o CMakeFiles/dvr.dir/potentials.f90.o CMakeFiles/dvr.dir/dvr_solvers.f90.o CMakeFiles/dvr.dir/main.f90.o -o dvr  /usr/lib/x86_64-linux-gnu/libblas.so  /usr/lib/x86_64-linux-gnu/liblapack.so  /usr/lib/x86_64-linux-gnu/libblas.so  /usr/lib/x86_64-linux-gnu/liblapack.so && :


Build finished

Output upon incuding use lapack in main program:

/opt/clion-2023.3.2/bin/cmake/linux/x64/bin/cmake --build /home/usrkm/CLionProjects/DVR/cmake-build-debug --target dvr -j 18 -v
Change Dir: '/home/usrkm/CLionProjects/DVR/cmake-build-debug'

Run Build Command(s): /opt/clion-2023.3.2/bin/ninja/linux/x64/ninja -v -j 18 dvr
[1/2] gfortran -I/home/usrkm/CLionProjects/DVR -g -fdiagnostics-color=always -llapack -fpreprocessed -c CMakeFiles/dvr.dir/main.f90-pp.f90 -o CMakeFiles/dvr.dir/main.f90.o
FAILED: CMakeFiles/dvr.dir/main.f90.o
gfortran -I/home/usrkm/CLionProjects/DVR -g -fdiagnostics-color=always -llapack -fpreprocessed -c CMakeFiles/dvr.dir/main.f90-pp.f90 -o CMakeFiles/dvr.dir/main.f90.o
/home/usrkm/CLionProjects/DVR/main.f90:7:6:

    7 |         use lapack
      |             1
Fatal Error: Cannot open module file ‘lapack.mod’ for reading at (1): No such file or directory
compilation terminated.
ninja: build stopped: subcommand failed.
5
  • Do you have an implementation of Lapack which provides modules, or Lapack95? A standard Netlib Lapack installation, for example, won't give you modules (because Fortran modules didn't exist 50 years ago). Commented Dec 23, 2023 at 14:23
  • I am just using the version that ships with Ubuntu 22 in /usr/lib (as in cmake above), both the lapack and blas directories contain liblapack.so.3 or libblas.so.3, from what I had read I thought that the compiler would generate the mod files from these Commented Dec 23, 2023 at 15:07
  • What exactly does it say? What is the complete output? Which exact compiler commands does CMake issue for you? See stackoverflow.com/questions/2670121/… and How to Ask. Never write "it says thatk. Always copy and paste the output. Commented Dec 23, 2023 at 16:00
  • To generate the .mod file for use lapack to work, the compiler needs to compile something with module lapack. This file may be shipped with your .deb package, but even if so you may need to generate the module files manually. Can you say exactly which package you use which provides the lapack library? Commented Dec 23, 2023 at 16:16
  • I have edited my question to include the output of the build. I believe I am using liblapack-dev from Ubuntu, I have not installed any additional packages such as Intel MKL. Commented Dec 23, 2023 at 16:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.