- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
This question was probably asked more than once, sorry. I could not find a solution of my problem.
MS VS 2008 + IFC 11.0
*******************FORTRAN*******************
Subroutine F
!DEC$ ATTRIBUTES DLLEXPORT::F,/abc/
!DEC$ ATTRIBUTES ALIAS: '_F@0' :: F
!DEC$ ATTRIBUTES ALIAS: '_abc' :: /abc/
real*8 a
common /abc/ a
write(*,*) "Test!"
write(*,*) a
end
****************c++**************************
#include
#pragma comment(lib,"fdll.lib")
using namespace std;
struct variables { double a; };
extern "C" {
extern struct variables abc;
void __stdcall F(); };
int main()
{
abc.a=1.0;
F();
return 0;
}
I tried '_abc' :: / abc /, '/ _abc /' :: / abc /, '_abc' :: abc - the result is the same.
I tried to use the BIND () - leads to the same error.
Please tell me what is my mistake?
Best regards.
This question was probably asked more than once, sorry. I could not find a solution of my problem.
MS VS 2008 + IFC 11.0
*******************FORTRAN*******************
Subroutine F
!DEC$ ATTRIBUTES DLLEXPORT::F,/abc/
!DEC$ ATTRIBUTES ALIAS: '_F@0' :: F
!DEC$ ATTRIBUTES ALIAS: '_abc' :: /abc/
real*8 a
common /abc/ a
write(*,*) "Test!"
write(*,*) a
end
****************c++**************************
#include
#pragma comment(lib,"fdll.lib")
using namespace std;
struct variables { double a; };
extern "C" {
extern struct variables abc;
void __stdcall F(); };
int main()
{
abc.a=1.0;
F();
return 0;
}
**********************************************
Error "Undefined symbol _abc".
I think that the error in! DEC $ ATTRIBUTES ALIAS: '_abc' :: / abc /I tried '_abc' :: / abc /, '/ _abc /' :: / abc /, '_abc' :: abc - the result is the same.
I tried to use the BIND () - leads to the same error.
Please tell me what is my mistake?
Best regards.
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You missed __declspec(dllimport) on the struct, like so:
extern __declspec(dllimport) struct variables abc;
Also, you should remove the __stdcall from the C++ and remove !DEC$ ATTRIBUTES ALIAS: '_F@0' :: F. If you ever think you need an alias with @n on the end, you're doing it wrong.
I would recommend using module variables and the standard C interoperability features instead of COMMON.
extern __declspec(dllimport) struct variables abc;
Also, you should remove the __stdcall from the C++ and remove !DEC$ ATTRIBUTES ALIAS: '_F@0' :: F. If you ever think you need an alias with @n on the end, you're doing it wrong.
I would recommend using module variables and the standard C interoperability features instead of COMMON.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
my question was stupid? :)
For some reason, nowhere in the articles "mix fortran and c++" I did't see mention of "extern __ declspec (dllimport) struct variables abc;" and BIND()
it worked, thanks!
For some reason, nowhere in the articles "mix fortran and c++" I did't see mention of "extern __ declspec (dllimport) struct variables abc;" and BIND()
it worked, thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Discussion of DLL export and import isn't really related to mixed-language - it applies to same-language programming too. While you can get away without a "dllimport" directive/pragma for routines, you can't for data.

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