-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add brief explanation on how to include stdlib in a Makefile #781
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @jannisteunissen . LGTM. It might be good to move also the lines 204-216 in this section, such that the section "Using stdlib in your project" contains the directives for CMake, Make, and fpm.
Apologies I'm no pkg-config expert. However, I think the reader may think that stdlib can be built directly using a makefile with this PR. So I would suggest to make it clear what step these instructions apply to:
The reported paths look OK (I haven't tested it). However, After install, we have a different scenario, because after a CMake build+install, folders are like Lines 2 to 4 in e88daa3
i.e., for example:
So if the user has run Also: an stdlib-fpm install is not currently supported and I think it's a good idea to have, I will open a PR for this so that then, one may also use the installed static library from the fpm branch. |
Thanks for explaining the directory structure. I will update this pull request. One question for @perazz :
Is there any need to specify this 'includedir'? I thought only the module path would be necessary. |
I would not worry about the general include folder, as I don't think that stdlib is ever going to include C headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you @jannisteunissen
Co-authored-by: Federico Perini <federico.perini@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you @jannisteunissen .
Let wait a few days, and if there are no more comments, we could merge it.
It might be useful to have more explicit instructions for people who get confused compiling things (like me). I didn't find it immediately obvious how go from the current draft content to compiling programs. For what it's worth I would tend to do something like this, which is probably derived from since-deleted stdlib documentation.
Perhaps my point could be addressed if we add another line showing how the variables should affect the calls to the compiler? |
Which doc do you refer to? |
@jvdp1 I just dug out an old variant of the README -- the relevant section is copied below. Using stdlib in your projectThe stdlib project exports CMake package files and pkg-config files to make stdlib usable for other projects. For CMake builds of stdlib you can find a local installation with find_package(fortran_stdlib REQUIRED)
...
target_link_libraries(
${PROJECT_NAME}
PRIVATE
fortran_stdlib::fortran_stdlib
) To make the installed stdlib project discoverable add the stdlib directory to the For non-CMake build systems (like make) you can use the exported pkg-config file by setting STDLIB_CFLAGS := $(shell pkg-config --cflags fortran_stdlib)
STDLIB_LIBS := $(shell pkg-config --libs fortran_stdlib) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for following this up, it could help make stdlib more accessible.
libdir=$(build_dir)/src | ||
moduledir=$(build_dir)/src/mod_files | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a something like below, to cover the case of compiling in a shell script or naively from the command line? I don't have much expertise on build systems, and often write small scripts to build programs.
Using stdlib when compiling within a script, or on the command line
This example uses pkg-config to manage the compiler flags.
export PKG_CONFIG_PATH=${install_dir}/lib/pkgconfig:$PKG_CONFIG_PATH
export STDLIB_CFLAGS=$(pkg-config --cflags fortran_stdlib)
export STDLIB_LIBS=$(pkg-config --libs fortran_stdlib)
export FC=gfortran
export FFLAGS="-O3 -flto"
# Compile
$FC $FFLAGS -c $STDLIB_CFLAGS my_program.f90
# Link
$FC $FFLAGS -o my_program my_program.o $STDLIB_LIBS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the information on pkg-config would certainly be nice to include as well, I can do that. I am a little hesitant to include actual compile rules, since these will depend on the particular compiler used and perhaps also on other things. To explain this clearly to people who are not familiar with Makefiles and compilation rules could take too much space. Instead, it could be nice to include a few worked-out usage examples with Makefiles in a separate location.
```make | ||
libdir=$(build_dir)/src | ||
moduledir=$(build_dir)/src/mod_files | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it would be good to see an example of how libdir
and moduledir
would be used inside the makefile to affect the compiler flags.
Just a small cosmetic suggestion: maybe use this: https://gist.github.com/pierrejoubert73/902cc94d79424356a8d20be2b382e1ab to add collapsible regions in the readme. It would be a good way to keep the view of the online version compact yet enable adding complete examples for each use case (?) Question: does pkg-config work on Windows? if so, a batch equivalent of the shell example could be useful. |
Update: I have now included an example of how to use pkg-config in a Makefile, which includes examples of compilation rules. I have left out details about defining targets etc, so I believe it is fine without a 'foldable' section. I have also clarified how the |
The current documentation on how to use stdlib in a project focuses on Cmake, see https://github.com/fortran-lang/stdlib?tab=readme-ov-file#using-stdlib-in-your-project
It can seem as is you actually need CMAKE to include stdlib (I got this impression). I think it would also be helpful to describe how to include stdlib in a regular makefile. This small change includes such documentation. I was not 100% sure about the paths: is it correct that the library is always in <build_folder>/src?