- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I want to call a C++ code from a Fortran code. I ended up with some problems at link time. To test a few things, I've done some very simple programs and did the following :
icc -c simple-c++.c
ifort -c gFASTdemo-fortran.f90
ifort gFASTdemo-fortran.o simple-c++.o -o main
wheresimple-c++.c is valid for both c and c++. It worked nicely. Then, I did
cpsimple-c++.csimple-c++.cpp
icc -c simple-c++.cpp
ifort -c gFASTdemo-fortran.f90
ifort gFASTdemo-fortran.o simple-c++.o -o main
and I now have the following output :
gFASTdemo-fortran.o: In function `MAIN__':
gFASTdemo-fortran.f90:(.text+0x3d9): undefined reference to `gFastVis'
simple-c++.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
I understand that Fortran is interoperable with C and not with C++. But, is there a workaround to make it work with C++ ?
Francois
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can call from Fortran a routine within a C++ source file if the routine is declared to have C linkage. For example:
extern "C" {...};
extern "C" {...};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You will also require -lstdc++ appended to your link command.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page