- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've been trying to call different Fortran functions from C++. But it looks to me, the C++ functioncompiled byVC++2005can only call 1Fortran function(IVF 9.1). For example, if a Fortran file (f1.f90) has two Fortran functions ( F1, F2)
subroutine F1()
end subroutine
subroutine F2()
end subroutine
I am wondering, from the C++ function, how to call that two functions(F1 and F2). The following code is not working
void F1();
void F2();
int main()
{
F1();
F2();
}
Thank you in advance!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
extern "C" void F1_();...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your pointing out the missed extern "C". I did have that in my computer. I guess my problem is how to call a Fortran subroutine in module from visual C++. I can not even access a variable in the module. Here is my code.
Visual C++:
#include
"stdafx.h"#ifdef
__cplusplusextern
"C"#endif
extern
"C" int EXAMP_mp_A;int
main(){
printf(
"test_mp_a %5.1f",EXAMP_mp_A);return 0;}
Here is my fortran code:
module
EXAMPINTEGER
A!DEC$ ATTRIBUTES DLLEXPORT::EXAMP
contains
subroutine
MODFUN! Expose subroutine MODFUN to users of this DLL!write(*,*) "Call from fortran"! Variables! Body of MODFUNend subroutine
MODFUNend module
EXAMPThe compiling error is
C_CALL_MOD.obj : error LNK2001: unresolved external symbol _EXAMP_mp_A
Anyone can help me out?
Thank you in advance!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
!DEC$ ATTRIBUTES DLLEXPORT::MODFUN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm a little confused - I thought you were using static library. Anyway, the DLLEXPORT attribute for a module name has no effect (though it's allowed).
It is somewhat more portable to export only stand-alone subprograms, not module procedures - this way you avoid the name mangling (which is probably fixed forever by Intel compilers, but may differ with other compilers).
Alas, if you want to do the same for variables, you have to resort to the old ugly common blocks. Or wait for the C interop stuff.
By the way, the double extern "C" you specify in your C++ header is redundant. The one specified within the #ifdef block suffices.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page