- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, everybody!
I'm trying touse my own allocation routinefor dynamic common...
Using Visual Studio .NET 2003 C++, I create the LIB, which exports the required routine:
extern "C" void _FTN_ALLOC(void **mem, int *size, char *name);
Then I link this LIB to my Fortran code, but run-time library still uses it's default version of _FTN_ALLOC routine. I've played with the order of linkage (in command line) but without effect.
So,what is the right way of linking the allocation routine(using only IDE settings preferably)?
Thanks in advance.
-- Andrew
Link Copied
8 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Open the Fortran project property page, select Linker, Input. In the field for Force Symbol References, type in _FTN_ALLOC. This will tell the linker to pull in the symbol.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lolt!! It works, but with little modification - Force Symbol References has to be set to __FTN_ALLOC (2 leading underscores).
And here isa continuation of the question... I'm trying to link legacy Fortran LIB to C++. The Fortran code uses huge COMMON block, which I wish to allocate dynamically in C++.
Is it possible to define _FTN_ALLOC routine just in main CPP file so that run-time Fortran library can use it? The trick with Forced Symbol References does not work here...
-- Andrew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't fully understand your last question, but I will point out that if you are putting this routine in a .lib, you will need something that references it in the Fortran project to pull it in. Ideally, an EXTERNAL statement would do it, but there's a bug at the moment where it doesn't.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Probably a simple example can better explain what I want... :)
---< Fortran code in myFort.LIB>---
subroutine myFortranSub()
COMMON /myCommon/ Array
!...
do i=1, N
Array(i) = ...
enddo
end subroutine
----------------------------
myFort.lib is compilled with parameter -Qdyncom:myCommon.
subroutine myFortranSub()
COMMON /myCommon/ Array
!...
do i=1, N
Array(i) = ...
enddo
end subroutine
----------------------------
myFort.lib is compilled with parameter -Qdyncom:myCommon.
-----< C++ code >-----
int gMemSize;
int gMemSize;
extern "C" void _FTN_ALLOC(void **mem, int *size, char *name)
{
//allocate memory for COMMON /myCommon/ in myFortranSub();
*mem = new BYTE[gMemSize];
}
{
//allocate memory for COMMON /myCommon/ in myFortranSub();
*mem = new BYTE[gMemSize];
}
void main()
{
//...
gMemSize = userDefinedMemSize;
myFortranSub();
//...
}
----------------------
{
//...
gMemSize = userDefinedMemSize;
myFortranSub();
//...
}
----------------------
In short, I link myFort.LIB to C++ project and expect that Fortran run-time library will use the provided _FTN_ALLOC for COMMON /myCommon/ allocation.
But this does not work. Probably correct compiler's/linker's parameters could help, but I cant find which. So, help please...
But this does not work. Probably correct compiler's/linker's parameters could help, but I cant find which. So, help please...
--Andrew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Andrew,
It should work - it does when I try to turn your example into something I can build. I have attached a ZIP of my working project. Compare it against what you have to see what's different.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Andrew,
It should work - it does when I try to turn your example into something I can build. I have attached a ZIP of my working project. Compare it against what you have to see what's different.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Many thanks, Steve! Your project works fine on my system too. And I find the differences with my project options...
My project uses dynamic run-time libraries, andyour example uses static run-time libs. Moreover, your example also does not work as expected (provided _FTN_ALLOC roitine does not called), if I change"Runtime Library" setting from staticto dynamic (no matter Multi-threaded or Single-threaded)...
This can be a solution, but my C++ program must be linked against Multi-threaded DLL (as required by wxWidgets framework)... Any suggestions?
--Andrew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You cannot use the dynamic common feature when specifying that the Fortrtan libraries should use the DLL form. The reason is that the Fortran RTL makes the external reference to __FTN_ALLOC and there is no way to have that reference resolved to your routine as the DLL is already linked. I see that the manual fails to mention this - I will report it to the writers.
Unless you can find a way to link against the static Fortran libraries, you will need to look for an alternate solution.I don't know if there is a way to resolve the problems caused by using the static Fortran RTL with DLL C RTL.

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