# FPM: compiler flags when compiling C files?

**URL:** <https://fortran-lang.discourse.group/t/fpm-compiler-flags-when-compiling-c-files/2083>\
**Category:** Help\
**Created:** [October 16, 2021, 3:04am UTC](https://fortran-lang.discourse.group/t/fpm-compiler-flags-when-compiling-c-files/2083 "2021-10-16T03:04:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hsnyder](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/hsnyder/32/747_2.png) [@hsnyder](https://fortran-lang.discourse.group/u/hsnyder)\
**Post date:** [October 16, 2021, 3:04am UTC](https://fortran-lang.discourse.group/t/fpm-compiler-flags-when-compiling-c-files/2083/1 "2021-10-16T03:04:52Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![awvwgk](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/awvwgk/32/154_2.png) [@awvwgk](https://fortran-lang.discourse.group/u/awvwgk)\
**Post date:** [October 16, 2021, 8:34am UTC](https://fortran-lang.discourse.group/t/fpm-compiler-flags-when-compiling-c-files/2083/2 "2021-10-16T08:34:21Z")

</div>

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

> <https://github.com/fortran-lang/fpm/commit/dfeb17a3811054716828be47644ac98b146746de>
>
> \- Read Fortran compiler from FPM\_FC or --compiler (deprecate FPM\_COMPILER)
> \- Re…ad Fortran compiler options from FPM\_FFLAGS or --flag
> \- Read C compiler from FPM\_CC or --c-compiler (deprecate FPM\_C\_COMPILER)
> \- Read C compiler options from FPM\_CFLAGS or --c-flag
> \- Read archiver from FPM\_AR or --archiver
> \- Read linker options from FPM\_LDFLAGS or --link-flag

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

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [October 16, 2021, 1:27pm UTC](https://fortran-lang.discourse.group/t/fpm-compiler-flags-when-compiling-c-files/2083/3 "2021-10-16T13:27:13Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![hsnyder](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/hsnyder/32/747_2.png) [@hsnyder](https://fortran-lang.discourse.group/u/hsnyder)\
**Post date:** [October 16, 2021, 2:38pm UTC](https://fortran-lang.discourse.group/t/fpm-compiler-flags-when-compiling-c-files/2083/4 "2021-10-16T14:38:50Z")

</div>

Thank you both!

---

<div class="post-metadata">

**Author:** ![awvwgk](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/awvwgk/32/154_2.png) [@awvwgk](https://fortran-lang.discourse.group/u/awvwgk)\
**Post date:** [October 16, 2021, 4:49pm UTC](https://fortran-lang.discourse.group/t/fpm-compiler-flags-when-compiling-c-files/2083/5 "2021-10-16T16:49:14Z")

</div>

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:

> **[Actions · fortran-lang/fpm](https://github.com/fortran-lang/fpm/actions/workflows/release.yml)**
>
> Fortran Package Manager (fpm). Contribute to fortran-lang/fpm development by creating an account on GitHub.

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

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [October 16, 2021, 10:51pm UTC](https://fortran-lang.discourse.group/t/fpm-compiler-flags-when-compiling-c-files/2083/6 "2021-10-16T22:51:59Z")

</div>

IMO2. If anyone else is looking try opening the URL [https://github.com/fortran-lang/fpm/suites/4072746231/artifacts/103567506](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).

---

<div class="post-metadata">

**Author:** ![awvwgk](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/awvwgk/32/154_2.png) [@awvwgk](https://fortran-lang.discourse.group/u/awvwgk)\
**Post date:** [October 17, 2021, 7:32am UTC](https://fortran-lang.discourse.group/t/fpm-compiler-flags-when-compiling-c-files/2083/7 "2021-10-17T07:32:59Z")

</div>

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](https://github.com/fortran-lang/fpm/pull/569). Feedback is welcome.

> [@urbanjost](#):
>
> 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 …”.

The workflow step for the single file version is here:

> <https://github.com/fortran-lang/fpm/blob/beeb481aa9ffdeca375fec8ce7a9543190a7b346/.github/workflows/release.yml#L67-L74>

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

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [October 17, 2021, 1:30pm UTC](https://fortran-lang.discourse.group/t/fpm-compiler-flags-when-compiling-c-files/2083/8 "2021-10-17T13:30:49Z")

</div>

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.
