# Where are the C Libraries that use iso\_c\_binding?

**URL:** <https://fortran-lang.discourse.group/t/where-are-the-c-libraries-that-use-iso-c-binding/4396>\
**Category:** Uncategorized\
**Created:** [September 23, 2022, 2:50pm UTC](https://fortran-lang.discourse.group/t/where-are-the-c-libraries-that-use-iso-c-binding/4396 "2022-09-23T14:50:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![giraffe](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@giraffe](https://fortran-lang.discourse.group/u/giraffe)\
**Post date:** [September 23, 2022, 2:50pm UTC](https://fortran-lang.discourse.group/t/where-are-the-c-libraries-that-use-iso-c-binding/4396/1 "2022-09-23T14:50:47Z")

</div>

Are there any C libraries on the Internet that use iso\_c\_binding? If there are libraries what are the URLs to that library or libraries?

What about complex iso\_c\_binding examples/programs on the Internet that use derived types? Are there any complete but complex working examples?

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:** [September 23, 2022, 2:57pm UTC](https://fortran-lang.discourse.group/t/where-are-the-c-libraries-that-use-iso-c-binding/4396/2 "2022-09-23T14:57:08Z")

</div>

I gave a presentation on using derived types defined in Fortran via `iso_c_binding` in C and other languages ([Using objects across language boundaries — Fortran OOP Seminar Series](https://awvwgk.github.io/foopss/)). It also links in the summary to two production projects which make of this feature in quite some different way.

Another different example might be the Fortran bindings for nlopt: [nlopt-f/nlopt\_interface.F90 at main · grimme-lab/nlopt-f · GitHub](https://github.com/grimme-lab/nlopt-f/blob/main/src/nlopt_interface.F90), which provide `iso_c_binding` interfaces for the procedures and types defined in [nlopt/nlopt.h at master · stevengj/nlopt · GitHub](https://github.com/stevengj/nlopt/blob/master/src/api/nlopt.h).

However, for both cases only one of the languages needs full access to the internals, while the other is using a rather opaque representation and performing actions via API calls.

There are probably many more examples, some can be found by searching for [source files using `iso_c_binding` on GitHub](https://github.com/search?q=iso_c_binding&type=code).

---

<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:** [September 23, 2022, 6:23pm UTC](https://fortran-lang.discourse.group/t/where-are-the-c-libraries-that-use-iso-c-binding/4396/3 "2022-09-23T18:23:09Z")

</div>

An early project where I started learning about C interoperability is [Brad Richardson / SQLite for Fortran · GitLab](https://gitlab.com/everythingfunctional/sqliteff)

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [September 23, 2022, 7:45pm UTC](https://fortran-lang.discourse.group/t/where-are-the-c-libraries-that-use-iso-c-binding/4396/4 "2022-09-23T19:45:37Z")

</div>

I’ve always wanted Redis in Fortran, I hope somebody makes it as a learning experiment.

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [September 23, 2022, 9:37pm UTC](https://fortran-lang.discourse.group/t/where-are-the-c-libraries-that-use-iso-c-binding/4396/5 "2022-09-23T21:37:35Z")

</div>

The question in the title is somewhat ambiguous. Are you interested in examples of Fortran apps/libraries calling C, or C apps/libraries which call Fortran? Personally, I’d say the former is more common; in the other direction it’s more common to see Python calling Fortran via C-conforming interfaces. But there’s still a lot of code in the wild which doesn’t use the standard interoperability, LAPACK is one of them.

A few projects I used as stepping stones to learn about Fortran-C interoperability include:

- [Fortran METIS Interface](https://ivan-pi.github.io/fmetis/)
- [GitHub - ivan-pi/Fortran-KaHIP-Interface: A modern Fortran interface to the KaHIP graph partitioning framework](https://github.com/ivan-pi/Fortran-KaHIP-Interface)
- [GitHub - ivan-pi/fortran-flann: Fortran bindings to the FLANN library for performing fast approximate nearest neighbor searches in high dimensional spaces.](https://github.com/ivan-pi/fortran-flann)  
[GitHub - ivan-pi/kdtree: A simple C library for working with KD-Trees](https://github.com/ivan-pi/kdtree)
- [GitHub - ivan-pi/libdogleg-f: Fortran bindings to libdogleg - a large-scale nonlinear least-squares optimization library](https://github.com/ivan-pi/libdogleg-f)
- [GitHub - ivan-pi/Fortran-RInside: Demonstration of Fortran interface to Rinside](https://github.com/ivan-pi/Fortran-RInside)

I also have snippets of code showing Fortran bindings to parts of nanoflann (C++), BLIS (C), Eigen++ (C++), and the C standard library, and the C++ standard template library. For one project I connected the widgets in a Python Jupyter notebook to an eigenvalue computation in Fortran via a Cython bridge.

---

<div class="post-metadata">

**Author:** ![nicholaswogan](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@nicholaswogan](https://fortran-lang.discourse.group/u/nicholaswogan)\
**Post date:** [September 24, 2022, 4:58pm UTC](https://fortran-lang.discourse.group/t/where-are-the-c-libraries-that-use-iso-c-binding/4396/6 "2022-09-24T16:58:42Z")

</div>

This is the most complicated iso\_c\_binding project I have ever done: [GitHub - Nicholaswogan/fortran-yaml-c](https://github.com/Nicholaswogan/fortran-yaml-c)

It uses recursion and derived types and a big web of pointers to make a fortran interface to a C yaml parser.

Also, I have a repo showing how to make a python interface to fortran using iso\_c\_binding and cython: [GitHub - Nicholaswogan/fortran-cython-examples](https://github.com/Nicholaswogan/fortran-cython-examples)
