# Problems linking Fortran/C++ code on Mac OS X

**URL:** <https://fortran-lang.discourse.group/t/problems-linking-fortran-c-code-on-mac-os-x/2051>\
**Category:** Help\
**Created:** [October 11, 2021, 6:40pm UTC](https://fortran-lang.discourse.group/t/problems-linking-fortran-c-code-on-mac-os-x/2051 "2021-10-11T18:40:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wclodius](https://avatars.discourse-cdn.com/v4/letter/w/87869e/32.png) [@wclodius](https://fortran-lang.discourse.group/u/wclodius)\
**Post date:** [October 11, 2021, 6:40pm UTC](https://fortran-lang.discourse.group/t/problems-linking-fortran-c-code-on-mac-os-x/2051/1 "2021-10-11T18:40:59Z")

</div>

I am trying to compare the results of a C++ hash function with the Fortran translation of that function. I therefore want to link the Fortran function, a Fortran driver, the original C++ code, and an “Extern C” wrapper for the C++ code. I do my work on a MacBook Pro, that runs an Intel processor, under MacOS 11.6. I’m attempting to use GNU Fortran (`gfortran`) and GNU C++ (`g++`), as installed using [Mac Ports](https://www.macports.org). The installed compilers don’t know the location of the system include files or libraries, so I am manually providing links to the directories with the link command. Everything now goes well until the link command where I get

```auto
    ...% make -f Makefile.validation

    gfortran -O3 -I../../mod_files -J./mod_files -L../../ -L./ -L/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/ \
    test_64_bit_hash_validation.o \
    spooky_wrapper.o \
    -lfortran_stdlib -lc_hash \
     -o test_64_bit_hash_validation -

    gfortran: error: -E or -x required when input is from standard input

```

As near as I can tell the reported error `gfortran: error: -E or -x required when input is from standard input` implies that “gfortran” thinks I am asking for the compilation of code being input through `stdin`, e.g., I am piping the source code to the command line . This leads to the following questions:

1. Is there a better forum for this problem?
2. Is my interpretation of the message correct?
3. What am I doing wrong?
4. How do I fix the problem?

---

<div class="post-metadata">

**Author:** ![wclodius](https://avatars.discourse-cdn.com/v4/letter/w/87869e/32.png) [@wclodius](https://fortran-lang.discourse.group/u/wclodius)\
**Post date:** [October 11, 2021, 6:47pm UTC](https://fortran-lang.discourse.group/t/problems-linking-fortran-c-code-on-mac-os-x/2051/2 "2021-10-11T18:47:40Z")

</div>

Never mind. The problem is the hyphen at the end of the link command.

---

<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 11, 2021, 6:55pm UTC](https://fortran-lang.discourse.group/t/problems-linking-fortran-c-code-on-mac-os-x/2051/3 "2021-10-11T18:55:52Z")

</div>

Yes, this is the right forum. I am glad you figured it out.

---

<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:** [October 11, 2021, 10:38pm UTC](https://fortran-lang.discourse.group/t/problems-linking-fortran-c-code-on-mac-os-x/2051/4 "2021-10-11T22:38:07Z")

</div>

@wclodius I’ve recently been doing some Fortran/C++ mix. I ran across some cites saying you need to use the C++ linker at the end to [make sure thing work properly.](https://www.ibm.com/docs/en/xl-fortran-aix/15.1.2?topic=calls-mixing-fortran)

> When mixing Fortran and C++ in the same program, you need to invoke the C++ compiler to correctly link the final program.

I’ve noticed that sometimes when I link with `gfortran` instead (which still “looks” like it works at first), then there is strange behavior. For example, C++ exceptions, which should be caught, never get caught.
