- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
I am trying to incorporate a C++ header file into my Fortran project in Visual Studio 2019 using IFORT. This header file includes two other C++ header files. I've included all three under 'Source Files' and enabled the preprocessor. In the Fortran file where I need to reference the C++ header file, I have
```
#include 'header.h'
```
but when I compile, I just get a "Bad # preprocessor line" warning. How do I make it so this header file can be used in my Fortran files? Do I need to add additional commands for compiling, or should VS be able to handle that automatically?
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
You can't do this. You'll have to write a Fortran version of the file as a module and USE the module. Fortran has extensive C interoperability features, but be aware that C++ procedures can't use any interface features not in C. (There are some additional limitations.) Any C++ procedures you want to call from Fortran must have the extern "C" prefix
Link kopiert
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Preprocessing is not enabled by default (and unlike on some other platforms, the case of the file type is ignored). You can turn it on in the project properties. Or, you can use INCLUDE. I assume you are aware that the Fortran compiler won't be happy with C/C++ language syntax.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
That's what I'm trying to find the answer to. It's a C++ file with various constants, types, and functions declared in C++. I need to access those in Fortran. Do I have to compile the header file using the C++ compiler first?
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
You can't do this. You'll have to write a Fortran version of the file as a module and USE the module. Fortran has extensive C interoperability features, but be aware that C++ procedures can't use any interface features not in C. (There are some additional limitations.) Any C++ procedures you want to call from Fortran must have the extern "C" prefix
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
I see. Just for additional details, the C++ header files are used to compile C++ code which will then reference a couple static libraries. Since the purpose of the header file is to let the new code know what the interface to the libraries is, I would have to write a Fortran file that gives the interface instead, and then just include those libraries as external dependencies. Am I understanding this right?
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Exactly right.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Sweet. I understand now. I'll get working on that then. Thanks!

- RSS-Feed abonnieren
- Thema als neu kennzeichnen
- Thema als gelesen kennzeichnen
- Diesen Thema für aktuellen Benutzer floaten
- Lesezeichen
- Abonnieren
- Drucker-Anzeigeseite