# How to pass compiling and linking flags to fpm

**URL:** <https://fortran-lang.discourse.group/t/how-to-pass-compiling-and-linking-flags-to-fpm/4404>\
**Category:** Help\
**Created:** [September 25, 2022, 2:53pm UTC](https://fortran-lang.discourse.group/t/how-to-pass-compiling-and-linking-flags-to-fpm/4404 "2022-09-25T14:53:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![icpup](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@icpup](https://fortran-lang.discourse.group/u/icpup)\
**Post date:** [September 25, 2022, 2:53pm UTC](https://fortran-lang.discourse.group/t/how-to-pass-compiling-and-linking-flags-to-fpm/4404/1 "2022-09-25T14:53:24Z")

</div>

I have a local library and module files not in current working directory. I need compile and link a new project to this library using fpm. Where should I modify the fpm.toml or pass the flag to the fpm command?

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [September 25, 2022, 5:00pm UTC](https://fortran-lang.discourse.group/t/how-to-pass-compiling-and-linking-flags-to-fpm/4404/2 "2022-09-25T17:00:09Z")

</div>

See [Manifest reference — Fortran Package Manager](https://fpm.fortran-lang.org/en/spec/manifest.html#specifying-dependencies) (specifying-dependencies)

You can also use the `--flag` option, for example:

```bash
$ fpm run --flag '$(pkg-config --cflags mylibrary)'

```

---

<div class="post-metadata">

**Author:** ![icpup](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@icpup](https://fortran-lang.discourse.group/u/icpup)\
**Post date:** [September 25, 2022, 10:26pm UTC](https://fortran-lang.discourse.group/t/how-to-pass-compiling-and-linking-flags-to-fpm/4404/3 "2022-09-25T22:26:04Z")

</div>

The reason I am asking for help here is that it is difficult for me to understand some description in Manifest reference. Maybe I need some tutorials on how to link local library to a project. Anyway, here is my situation: I have a local library `libmylib.a` at `~/mine/lib` and the related mod files at `~/mine/include`. Based on [Manifest:link external library](https://fpm.fortran-lang.org/en/spec/manifest.html#link-external-libraries), the build section is modified as

```auto
[build]
link = "mylib"

```

However, where do I specify the the path for lib and mods? When compile and link using gfortran, the command used was  
`gfortran -I~/mine/include -L~/mine/lib main.f90 -lmylib`

---

<div class="post-metadata">

**Author:** ![gnikit](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/gnikit/32/1213_2.png) [@gnikit](https://fortran-lang.discourse.group/u/gnikit)\
**Post date:** [September 26, 2022, 10:53am UTC](https://fortran-lang.discourse.group/t/how-to-pass-compiling-and-linking-flags-to-fpm/4404/4 "2022-09-26T10:53:25Z")

</div>

There are a few different ways that this can be done in fpm.

- If you have **local includes** specify them in the `"include-dir" = ["mylocalinc"]` keyword. Keep in mind this

> _include-dir_ does not currently allow using pre-built module `.mod` files

- If you have includes outside of your project either:
  - Use the fpm subcommand `--flag` to pass whatever compiler options you want to fpm
  - Set the shell variable `FPM_FFLAGS` to pass whatever compiler options you want to fpm
  - Or last option, that I do not recommend but I list for completeness, append/prepend to the variable your compiler uses to look for include paths for GNU (gfortran) that is `CPATH` e.g. CPATH=${CPATH}:/my/path

For linking the options that you have are pretty much the same. In your `fpm.toml` add the lib you wish to link against to

```auto
[build]
link = ["mylib"]

```

- Use the fpm subcommand `--link-flag` e.g. `fpm build --link-flag "-L/path/to/mylib"`
- Set `FPM_LDFLAGS` e.g. `export FPM_LDFLAGS="-L/path/to/mylib"` and then `fpm build`
- Or set the compiler variables `LD_LIBRARY_PATH` (and for gfortran `LIBRARY_PATH`) to include your “/path/to/mylib” e.g. `export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/path/to/mylib`, `export LIBRARY_PATH=${LIBRARY_PATH}:/path/to/mylib` and then `fpm build`

Here is an example where you link against an external library is [GitHub - gnikit/gmsh-fpm: Gmsh API using the Fortran Package Manager (fpm)](https://github.com/gnikit/gmsh-fpm)

---

<div class="post-metadata">

**Author:** ![icpup](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@icpup](https://fortran-lang.discourse.group/u/icpup)\
**Post date:** [September 26, 2022, 11:48am UTC](https://fortran-lang.discourse.group/t/how-to-pass-compiling-and-linking-flags-to-fpm/4404/5 "2022-09-26T11:48:08Z")

</div>

Thank you very much. Very clear description.

---

<div class="post-metadata">

**Author:** ![ofmla](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ofmla/32/3320_2.png) [@ofmla](https://fortran-lang.discourse.group/u/ofmla)\
**Post date:** [May 22, 2024, 7:06pm UTC](https://fortran-lang.discourse.group/t/how-to-pass-compiling-and-linking-flags-to-fpm/4404/6 "2024-05-22T19:06:14Z")

</div>

I’m trying to get rid of `-Werror=implicit-interface` flag when compiling a project and I am passing my compiler flags via `--flag "compiler flags option of my choice "` but the `--verbose` option shows me that the project is still being compiled with `-Werror=implicit-interface`. What can I do to get it `-Werror=implicit-interface` out of the way?

---

<div class="post-metadata">

**Author:** ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)\
**Post date:** [May 22, 2024, 7:45pm UTC](https://fortran-lang.discourse.group/t/how-to-pass-compiling-and-linking-flags-to-fpm/4404/7 "2024-05-22T19:45:24Z")

</div>

You may want to try this: [Manifest reference — Fortran Package Manager](https://fpm.fortran-lang.org/spec/manifest.html#fortran-features)
