# FPM: Platform-specific instructions to linker on fpm.toml

**URL:** <https://fortran-lang.discourse.group/t/fpm-platform-specific-instructions-to-linker-on-fpm-toml/7296>\
**Category:** fpm\
**Created:** [January 30, 2024, 8:34am UTC](https://fortran-lang.discourse.group/t/fpm-platform-specific-instructions-to-linker-on-fpm-toml/7296 "2024-01-30T08:34:04Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![IanMartinAjzenszmidt](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ianmartinajzenszmidt/32/1992_2.png) [@IanMartinAjzenszmidt](https://fortran-lang.discourse.group/u/IanMartinAjzenszmidt)\
**Post date:** [February 6, 2024, 2:37pm UTC](https://fortran-lang.discourse.group/t/fpm-platform-specific-instructions-to-linker-on-fpm-toml/7296/13 "2024-02-06T14:37:11Z")

</div>

> [@amasaki203](#):
>
> Hi.
> 
> I’m using fpm v0.10.0 and writing code that utilizes C interoperability to use OS APIs. To support cross-platform compatibility, I’m switching build code using preprocessor directives, which works fine in general. However, I’ve noticed that I need to add specific instructions to the linker only for Windows.
> 
> I attempt to address this in the `fpm.toml` file with the following:
> 
> ```auto
> [build]
> auto-executables = true
> auto-tests = true
> auto-examples = true
> module-naming = false
> link = ["iphlpapi", "ws2_32"]
> 
> ```
> 
> Specifically, adding `link = ["iphlpapi", "ws2_32"]` to `fpm.toml` for successful Windows builds. However, it seems that this approach isn’t working well, as it causes linker errors on other operating systems (on the premise that `iphlpapi` and `ws2_32` libraries are specific to Windows).
> 
> How can I add platform-specific instructions to `fpm.toml` for successful builds on Windows without affecting builds on the other operating systems?

I cant guarantee that the following is correct, but it might be worth considering.  
To add platform-specific instructions to your `fpm.toml` file for successful builds on Windows without affecting builds on other operating systems, you can utilize conditional compilation supported by Fortran Package Manager (fpm). This approach allows you to specify different settings for different platforms.

In `fpm`, conditional settings can be specified using profile sections in the `fpm.toml` file. Each profile can include conditions based on the operating system, compiler, or build mode, which allows you to tailor the build process for different environments.

Here’s how you can modify your `fpm.toml` file to include Windows-specific linker instructions:

toml

```auto
[build]
auto-executables = true
auto-tests = true
auto-examples = true
module-naming = false

# Default linker settings for non-Windows platforms
link = []

# Windows-specific settings
[profiles.windows-x86_64]
link = ["iphlpapi", "ws2_32"]

```

In this example, the `[profiles.windows-x86_64]` section is used to specify settings that should only apply when building on a 64-bit Windows platform. The `link = ["iphlpapi", "ws2_32"]` line within this section adds the `iphlpapi` and `ws2_32` libraries to the linker settings, but only for Windows builds. The default `link = []` in the `[build]` section ensures that no additional libraries are linked for non-Windows platforms.

This approach should help you avoid linker errors on other operating systems while still including the necessary libraries for Windows builds. Remember to adjust the profile name and conditions according to your specific needs and the platforms you are targeting.

---

_[View the full topic](https://fortran-lang.discourse.group/t/fpm-platform-specific-instructions-to-linker-on-fpm-toml/7296)._
