Skip to content

Split --link-flag #604

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

Open
rouson opened this issue Nov 9, 2021 · 8 comments
Open

Split --link-flag #604

rouson opened this issue Nov 9, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@rouson
Copy link
Contributor

rouson commented Nov 9, 2021

Description

I believe that fpm's current --link-flag argument needs to be split into two arguments named something like --link-flag (same as before) and --link-lib, where a concatenated list of any --link-lib arguments would be placed at the end of the resulting link line. The motivating use case is explained below.

I'm working on a shell-script installer for a new package. The installer first installs the prerequisite GASNet-EX, which in turn defines several GASNET_* environment variables for use in building and linking against GASNet-EX. After installing GASNet-EX on macOS, a fpm command of the following form works to build the new package and link it against GASNet-EX:

fpm build  \
  --c-compile "$GASNET_CC" \
  --c-flag "$GASNET_CFLAGS $GASNET_CPPFLAGS" \
  --link-flag "$GASNET_LDFLAG $GASNET_LIBS"

where GASNET_LIBS contains the -L and -l flags for linking against GASNet-EX.

On Ubuntu, the above command fails, but if I copy the resulting gfortran link command and reuse it with $GASNET_LIBS moved to the tail end, linking succeeds.

Expected Behaviour

Successful linking.

Version of fpm

c5ef60d

Platform and Architecture

Ubuntu via GitHub Action

Additional Information

No response

@rouson rouson added the bug Something isn't working label Nov 9, 2021
@awvwgk
Copy link
Member

awvwgk commented Nov 9, 2021

Preferably we could put libraries we link against in the package manifest under build.link rather than injecting them via the command line options. The --link-flag is mainly meant to add -L flags to find libraries we want to link against from the package manifest or add linker options (like -Wl,-rpath, LTO, ...).

Would adding the required libraries in build.link be sufficient for your use case?

@awvwgk
Copy link
Member

awvwgk commented Nov 9, 2021

The --link-flag arguments from the model are purposely put in front of the object files here

target%link_flags = model%link_flags//" "//string_cat(target%link_objects," ")

@rouson
Copy link
Contributor Author

rouson commented Nov 9, 2021

Would adding the required libraries in build.link be sufficient for your use case?

I didn't know about build.link. I'll try it. Thanks for the quick reply!

@rouson
Copy link
Contributor Author

rouson commented Nov 19, 2021

In my use case, building on macOS worked but not on Linux. @awvwgk, your suggestion works on Linux but breaks the macOS build. For now, I think we have to come up with a way to use different fpm.toml files on one operating system versus another. Eventually one of the solutions proposed in issue #611 will likely be best, but it still might be a good idea to also have the option to specify -L and -l arguments separately from other link arguments and have the -L and -l arguments be placed at the end of the link command.

@jvdp1
Copy link
Member

jvdp1 commented Nov 19, 2021

I agree with @rouson that having the option to specify separately -L and -l in the argumetns would be a nice feature. This could be helpful to support multiple compilers with a same fpm.toml, with the -l argument added to the specified libs in the fpm.toml under [link].

@urbanjost
Copy link
Contributor

Haven't carefully read this discussion yet but I
always put -L and -l on the right side of my build objects in order as a result of working with single-pass left-to-right loaders; without trouble; but since multiple -flag options are allowed, perhaps a special option like --place [left|right] that would indicate the position to place subsequent options would be a stop-gap? Although nearly a standard, not all compilers necessarily use -L and -l so just looking for those flag names might have issues

@awvwgk
Copy link
Member

awvwgk commented May 26, 2022

@rouson Would native support for pkg-config in fpm be a solution for your library? I see that there is a generation step paring the GASNet-EX pkg-config file to build the fpm.toml at

https://github.com/BerkeleyLab/caffeine/blob/96ae0a818203ed92017e79bd3debb3b2f6e3c556/install.sh#L297-L303

We discussed pkg-config support in #439, but didn't arrive at an agreement whether fpm should support it or no.

@ivan-pi
Copy link
Member

ivan-pi commented Mar 18, 2025

pkg-config support was added in recent versions. Maybe that would be a way to move this issue forward?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants