- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, all, I have a really weird problem. I am trying to use Dllimport in C# (VS2005) to call a 64 bit fortran dll, the follows is my fortran program. This works fine. But if I change the statement "a=b" to "a(1)=b(1)" or "a(:)=b(:)"and try to load this dll in C#, it always throw me an exception tells me that unable to load the module. What I mean is that as long as I did some operation on some elements of an array in Fortran dll, the C# program cannot even load it though that dll compiles successfully. If I just do operation on the whole array in dll, like "a=b"C# works fine. That is really weird. I hope anyone can be helpful, thanks.
subroutine test(a,b,size)
!DEC$ ATTRIBUTES DLLEXPORT :: test
!DEC$ ATTRIBUTES ALIAS:'test' :: test
!DEC$ ATTRIBUTES REFERENCE :: a,b
!DEC$ ATTRIBUTESVALUE:: size
integer size
doubleprecision a(1:size)
doubleprecision b(1:size)
a = b
end subroutine test
Sam
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As an alternative, you can build your Fortran DLL linked to static libraries. In your application's environment, this will work fine. I don't recommend static linking of DLLs when native C/++ or Fortran code is also in the application.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Steve, thanks a lot for your explanation, it makes sense to me. As I tried other functions like
some math functions in my Fortran dll, then the C# project won't even load it. I guess your solution should work though I have not tried it.
I am new to Intel Fortran though I have been on C# for a while. The reason I use Fortran is we think if we
put heavy math operation in the Fortran Dll instead of C++/C# dll, the speed will be enhanced, do you think it will make huge difference?
I have another naive question. I am not sure in the Fortran dll, I can put some function (eg. FunctionA) to be EXPORTED, and some other
function (eg. FunctionB) is only called internally in Fortran dll by FunctionA. I tried it, but it did not work to me, after I write "call functionB" in
functionA, my C# project won't load that Fortran Dll, I guess that is maybe the same reason because I did not specify my Fortran Runtime DLL path in my
PATH enviorment or copied it to my C# working directory. I am wondering in Fortran, there is a big "system.dll" for "array operation, math functions, and call
another subroutine" or they are separated runtime DLLs in Fortran? Any idea under which directory I may find them? Thanks.
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your Fortran DLL will rely on one or more DLLs installed with Intel Visual Fortran. The folder containing these DLLs needs to be in the definition of the PATH environment variable, otherwise any DLL dependent on those DLLs won't load. Your own DLL needs to be wherever you say it is in the C# specification.
- 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