Every time when I try to install the fortran stdlib in MacOS with
brew tap fortran-lang/stdlib
brew install fortran-lang/stdlib/stdlib
and it shows me with the error
Cloning into '/opt/homebrew/Library/Taps/fortran-lang/homebrew-stdlib'...
Username for 'https://github.com': shiqsh
Password for 'https://xxxx@github.com':
remote: Repository not found.
fatal: repository 'https://github.com/fortran-lang/homebrew-stdlib/' not found
Error: Failure while executing; `git clone https://github.com/fortran-lang/homebrew-stdlib /opt/homebrew/Library/Taps/fortran-lang/homebrew-stdlib --origin=origin --template= --config core.fsmonitor=false` exited with 128.
So how to fix the error? and if there is a easy way to install the fortran-stdlib in MacOS?
Unless there is some magic I’m not aware of in the MacOS world (not a mac user), stdlib is not a package installable through any OS package manager. It is a source-code based library that you have to download, build and install, for instance using CMake or FPM. The instructions are here GitHub - fortran-lang/stdlib: Fortran Standard Library
As far as I’m aware, stdlib isn’t a package installable through brew any more than it is through aptitude, pacman, etc.. If you are using the Fortran Package Manager for your project, the easiest way is to simply include the stdlib metapackage by adding to following to your project’s toml file:
[dependencies]
stdlib = "*"
Simple and hassle-free. More info and alternatives are in the README in stdlib’s repository that @hkvzjal pointed to.
Hello! stdlib is a collection of modules and there is no such module as fortran_stdlib which you seem to be using in your in source file test_stdlib.f90
Instead a minimal testing source file could be this
program demo
use stdlib_ascii, only: is_lower
implicit none
print *, is_lower('a')
end program demo
Compile it with the following command (Don’t forget to link with the static library as below!)
This should produce an executable with the desired output.
of course the compile command can turn real messy real fast, you could try to shorten it by making use of pkgconfig, the pkgconfig file for stdlib is located at /opt/homebrew/Cellar/fortran-stdlib/0.7.0/lib/pkgconfig/fortran_stdlib.pc
If one does a google search on “homebrew fortran-stdlib”, then the AI Overview does indeed indicate that the command “brew install fortran-stdlib” is supported within the homebrew package manager.
I think this is the problem. Namely, what is the USE statement in your fortran code? That is what tells the compiler which module file to search for. Module files are created by the fortran compiler during the build of stdlib, and to use them afterwards, both the object file (somename.o) and the module file (modulename.mod) are used. I don’t know the details beyond that for stdlib, but it is likely that the *.o files are moved into an archive library so that only that one library needs to be searched during the load step (either ld, or by the fortran compiler itself). However, the *.mod files must usually be available themselves, not from a library of merged files.
Note the module name that is referenced in the USE statement.
Right now, and for the foreseeable future, each fortran compiler has its own *.mod file format, so individual compilers need to create their own files, and one compiler cannot access another compiler’s *.mod files.
I am not a fortran-stdlib user, so the above comments are just based on what the google search says.
many thanks. But I have another question that if I use FPM and add the code in my toml file, how can I use the fpm with openmp? also add something in the toml file?
All homebrew-installed pkg-config files (*.pc) get symlinked (at least in Linux, MacOS) to $HOMEBREW_PREFIX/lib/pkgconfig/ directory which makes them simple to add to PKG_CONFIG_PATH variable. Also, using $HOMEBREW_PREFIX instead of a hardcoded path like /opt/homebrew make the configuration, compiler options etc. as OS-independent as possible.
AFAIU (correct me if I am wrong, I’d love to be!), the above trick makes fpm download stdlib sources for every project that uses the library. I could not find a recipe for using a system/user installed stdlib in FPM projects (as it shows for CMake/Makefile projects), unless stdlib = "*" automagically finds the system-wide or user installation.
You are not wrong, and that’s one of the things that I personally don’t like about the current way fpm handles dependencies. I preferer to get the required packages locally and then declare the dependencies with the path option.
Now, FPM does enable you to “install” in the proper term Manifest reference — Fortran Package Manager which would then enable you to link against your pre-compiled static library.