Using stdlib in Ubuntu

Help me out please
I am facing issues in using stdlib on my local(ubuntu 20.04).
I followed the steps given in the readme file.
I have cloned the repo.
Then I created CMake files.

I have also added the path to this folder in my .bashrc file (The very last line of the image given below)

I don’t know how to import them into my project now can you please help me here.

Hello Chetan,

thanks for testing out stdlib. I guess our build instructions could be streamlined further.

Anyways, the procedure which worked for me on WSL was:

  1. Clone, build, and install stdlib
git clone https://github.com/fortran-lang/stdlib
cd stdlib
cmake -B build -DCMAKE_MAXIMUM_RANK=4 -DCMAKE_INSTALL_PREFIX=$HOME/.local
cmake --build build
cmake --install build
  1. Export the prefix path
export CMAKE_PREFIX_PATH=$HOME/.local/lib
  1. Create a test program calling stdlib and the CMake file
ipribec@thinkpad:/mnt/d/demo/my_code$ cat hello_stdlib.f90
program main

  use stdlib_linalg, only: diag
  implicit none

  real :: A(3,3), d(3)

  A = reshape([1.,2.,3.,4.,5.,6.,7.,8.,9.],[3,3])

  d = diag(A)

  write(*,*) d

end program
ipribec@thinkpad:/mnt/d/demo/my_code$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.14)

project(
  "demo"
  LANGUAGES "Fortran"
  VERSION "0.1"
)

find_package(fortran_stdlib REQUIRED)

add_executable(hello_stdlib hello_stdlib.f90)
target_link_libraries(
  hello_stdlib 
  PRIVATE fortran_stdlib::fortran_stdlib)
  1. Build and run your program
ipribec@thinkpad:/mnt/d/demo/my_code$ mkdir build
ipribec@thinkpad:/mnt/d/demo/my_code$ cd build
ipribec@thinkpad:/mnt/d/demo/my_code/build$ cmake ..
-- The Fortran compiler identification is GNU 9.3.0
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Check for working Fortran compiler: /usr/bin/f95 - skipped
-- Checking whether /usr/bin/f95 supports Fortran 90
-- Checking whether /usr/bin/f95 supports Fortran 90 - yes
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/d/demo/my_code/build
ipribec@thinkpad:/mnt/d/demo/my_code/build$ make hello_stdlib
Scanning dependencies of target hello_stdlib
[ 50%] Building Fortran object CMakeFiles/hello_stdlib.dir/hello_stdlib.f90.o
[100%] Linking Fortran executable hello_stdlib
[100%] Built target hello_stdlib
ipribec@thinkpad:/mnt/d/demo/my_code/build$ ./hello_stdlib
   1.00000000       5.00000000       9.00000000
2 Likes

That was really helpful and it worked for me.
Thank you @ivanpribec

We also provide an example integration that let’s you use stdlib within a CMake project here:

The advantage of this setup is that you don’t have to install and/or update stdlib separately, but build it on demand in the dependent project.

1 Like

Is there any simple gfortran based compilation example? I’m trying to avoid any build systems for some small experiments. Pure makefile would do.

Is there also any examples on how to use conda-based fortran-stdlib installation using simple gfortran?