Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have two choices. <br/> 1) I can show with example <br/></p> <p>FORTRAN</p> <pre><code>program ftest use iso_c_bindings implicit none interface function saythis(a) ! should be subroutine if saythis returns void import :: c_ptr type(c_ptr), value :: a end function saythis end interface character(len=80), target :: str type(c_ptr) cstr integer :: r str='Hello World From Fortran' // C_NULL_CHAR cstr=c_loc(str(1:1)) r=saythis(cstr) </code></pre> <p>C/C++</p> <pre><code>#ifdef __cpluscplus #include &amp;ltl;cstdio&amp;gt; using namespace std; #else #inlcude &amp;lt;stdio.h&amp;gt; #endif #ifdef __GNUC__ #define FORT(func) func ## _ #else #define FORT(func) __stdcall func ## _ #endif #ifdef __cpluscplus extern "C" { #endif __declspec(dllexport) int FORT(sayit)(char* c) { return printf("%s\n",c); } #ifdef __cpluscplus } #endif </code></pre> <p>This works w/gcc toolchain. You'll have to dumpbin on the DLL and fortran object code to see if the names match up correctly. <br/> The other way is similar:</p> <pre><code>//This is for gcc toolchain //you'll have to find the symbol conversion yourself //I think that Visual Studio converts fortran names //to ALL CAPS so instead of func =&gt; _func you'll need func =&gt; FUNC </code></pre> <p>FORTRAN</p> <pre><code>program ftest integer aa,bb,cc common/vari/aa,bb,cc aa=7 bb=11 cc=0 call dosomething call dosomethingelse(aa,bb,cc) </code></pre> <p>C/C++</p> <pre><code>#ifdef __cplusplus extern "C" { #endif int _dosomething(); int _dosomethingelse(int*,int*,int*); //all fortran is pass by reference struct { int aa,bb,cc; } vari; #ifdef __cplusplus } #endif //function def's go here //struct vari should be the same memory as common/vari block </code></pre> <p>COMPILE COMMAND</p> <pre><code>$&gt;g++ -c ctest.c &lt;br/&gt; $&gt;gfortran -c ftest.f90 &lt;br/&gt; $&gt;gfortran *.o -lstdc++ -o test_prog &lt;br/&gt; </code></pre> <p>Hope this helps</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload