|
建议你用标准的混编方法:ISO_C_Binding 不但在 VS+IVF 可以用,在其他编译器(gcc,gfortran)也可以用。 它是语法规范的标准用法。
[C++] 查看源码 复制源码 extern "C" {
void GETSTRING(char *A,
int LEN);
}
void main()
{
char STR[] = "hello";
GETSTRING(STR, strlen(STR));
return;
}[Fortran] 查看源码 复制源码 subroutine getstring(a,n) Bind( C , Name = "GETSTRING" ) !DEC$ ATTRIBUTES DLLEXPORT ::GETSTRING use ,Intrinsic::ISO_C_Binding implicit none type(C_PTR) , value :: a !c++主程序中传递进来的“a”变量,是C语言的指针 integer , value :: n !传入的字符串长度 character(len=n),pointer::pa !这是Fortran的字符串指针 call c_f_pointer( a , pa ) !把c语言的指针转换成fortran字符串指针 write(*,*) pa end subroutine |
| 有没有可能是fortran编译器版本的问题呢? |
|
C++源代码如下: [C++] 查看源码 复制源码 #include <stdio.h>
#include <windows.h>
#include <iostream>
#include <msclr\marshal_cppstd.h>
#include "float.h"
#include <string>
#include <math.h>
#include <cstring>
#include <vector>
#include <istream>
#include <fstream>
using namespace msclr::interop;
using namespace std;
extern "C" {
void __stdcall GETSTRING( char *A,
int LEN);
}
void main()
{
char STR[]="hello";
GETSTRING(STR,strlen(STR));
return;
}fortran代码如下: [Fortran] 查看源码 复制源码 subroutine getstring(a)
!DEC$ IF DEFINED (_DLL)
!DEC$ ATTRIBUTES DLLEXPORT ::GETSTRING
!DEC$ END IF
implicit none
character(len=*)::a
write(*,*)a
return
end subroutinefortran编译器为Intel Parallel Studio XE 2013, C++编译器为VS2012 |
| 请以文本(而非截图)的方式,贴出 C++ 代码和 fortran 代码。 |
捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )
GMT+8, 2025-11-6 06:47