FPM: compiler flags when compiling C files?

Hi everyone… fpm can compile .c files as well as Fortran files, but it doesn’t appear to respect the --flag argument when doing so. For example, if I say fpm build --flag '-fPIC', then -fPIC will be applied when compiling Fortran files, but not when compiling C files. Is there a workaround for this to get fpm to apply the flag when compiling C files as well?

I’m using fpm 0.4. Thanks!

1 Like

This is available in the latest version, but not released yet.

You can now specify compiler arguments for C with --c-flag.


Note that in addition to pulling and building the newer version of fpm(1) you can also compile the single-file version that you can see with a browser or use curl(1) or

mkdir tmp
cd tmp
wget https://raw.githubusercontent.com/urbanjost/fpm-tools/main/tools/bootstrap/fpm_20211010.F90
gfortran fpm_20211010.F90 -o fpm
1 Like

Thank you both!

Fpm is producing single file versions now for every commit (including PRs), you can go to the actions in the repo and select one of the release workflows. In the artifacts section you can download the single file version:

I’m also working on a proper deployment of those, because downloading them from the actions tab is a bit too complicated IMO.

1 Like

IMO2. If anyone else is looking try opening the URL https://github.com/fortran-lang/fpm/suites/4072746231/artifacts/103567506.

Great that is an automatic artifact. I see why you want to simplify accessing it though. github is not making that particuarly easy. I have seen it mentioned but never have used the artifacts. Seems like it would have to be limited in space or it seems like it could get unmanageable for github but have not looked at it too hard yet. Need to read up on that; but unless something like the URL above can be automatically added to a page somewhere it takes me less time to make my own than to find these. Look forward to seeing your solution though; seems like a really nice idea. Note that I have to put ‘#undef unix’ in mine or I cannot build it with ifort(1) unless I know to use “ifort -Uunix …”. It would be nice if that line were there; albeit I suspect it it predominantly built with gfortran. Might be other strings with other compilers too, but most predefined macros start with underscore (ifort predefines the macro “unix” which is a string that appears in the code, so when preprocessed because it ends in “.F90” the “unix” string gets expanded to a “1” and causes errors).

I didn’t post a direct link here because they expire quickly. The solution I have been working on can be found in Add workflow for continuous delivery by awvwgk · Pull Request #569 · fortran-lang/fpm · GitHub. Feedback is welcome.

The workflow step for the single file version is here:

I’m already defining FPM_BOOTSTRAP we can add an #undef unix there as well.

Adding the undef unix looks like it fits right into your method, which is great. The continious build makes it easier for users to test development versions, which addresses issues just like this post; now if we can add more unit tests ( including building some packages and running their unit tests as well(?)) your PR will really facilitate the speed at which we can review and propose changes with confidence. Great work.

1 Like