# Preprocessing with Clang

**URL:** <https://fortran-lang.discourse.group/t/preprocessing-with-clang/2145>\
**Category:** Help\
**Created:** [October 23, 2021, 7:04am UTC](https://fortran-lang.discourse.group/t/preprocessing-with-clang/2145 "2021-10-23T07:04:16Z")\
**Posts on this page:** 4\
**Page:** 1

<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 23, 2021, 7:04am UTC](https://fortran-lang.discourse.group/t/preprocessing-with-clang/2145/1 "2021-10-23T07:04:16Z")

</div>

I’m currently trying to package a project ([ELPA](https://elpa.mpcdf.mpg.de/)) which is using the C preprocessor for its Fortran source code with:

```nohighlight
${CPP:-cpp} -P -traditional

```

Now I’m building for a platform (OSX) where I don’t have GCC’s `cpp` but only clang (I can’t install or use GCC’s C compilers, but I have GFortran). I tried with

```nohighlight
${CC:-clang} -E -P --traditional-cpp

```

But didn’t get it to work with the actual Fortran source in the project. Since I’m packaging this project I don’t have much control over their build system (autoconf) or their tool chain support, but I can slightly patch around things (which I’m already doing).

Does anyone here have experience with using clang for preprocessing Fortran source? Also, any hack to get around the preprocessing issue would be appreciated as well ;).

In case anyone is interested, here is my attempt to build ELPA on OSX: [Support build for OSX by awvwgk · Pull Request #1 · conda-forge/elpa-feedstock · GitHub](https://github.com/conda-forge/elpa-feedstock/pull/1)

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [October 23, 2021, 3:51pm UTC](https://fortran-lang.discourse.group/t/preprocessing-with-clang/2145/2 "2021-10-23T15:51:03Z")

</div>

I have used `gfortran -E -cpp` to preprocess on a Mac. It seems to work. Is that an option for you?

---

<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 23, 2021, 4:12pm UTC](https://fortran-lang.discourse.group/t/preprocessing-with-clang/2145/3 "2021-10-23T16:12:26Z")

</div>

That seems to do the trick, I went with:

```nohighlight
${FC:-gfortran} -E -P -cpp

```

I wonder why this doesn’t work with clang at all? For a potential future Windows build I would have to go with a clang/flang combination and can’t reuse this trick.

At least the preprocessing works now, of course the C source fails to compile with clang…

---

<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 23, 2021, 4:24pm UTC](https://fortran-lang.discourse.group/t/preprocessing-with-clang/2145/4 "2021-10-23T16:24:22Z")

</div>

Sigh, seems to be a futile undertaking anyway. The project wasn’t developed with other systems than Linux in mind and they use a bunch of system function which are not portable, like `sched_getcpu(3)`.
