Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

dynamic common _FTN_ALLOC routine

andrewnovikov
Beginner
958 Views

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

0 Kudos
8 Replies
Steven_L_Intel1
Employee
958 Views
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.
0 Kudos
andrewnovikov
Beginner
958 Views
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
0 Kudos
Steven_L_Intel1
Employee
958 Views
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.
0 Kudos
andrewnovikov
Beginner
958 Views
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.
-----< C++ code >-----
int gMemSize;
extern "C" void _FTN_ALLOC(void **mem, int *size, char *name)
{
//allocate memory for COMMON /myCommon/ in myFortranSub();
*mem = new BYTE[gMemSize];
}
void main()
{
//...
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...

--Andrew
0 Kudos
Steven_L_Intel1
Employee
958 Views
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.
0 Kudos
Steven_L_Intel1
Employee
958 Views
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.
0 Kudos
andrewnovikov
Beginner
958 Views
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
0 Kudos
Steven_L_Intel1
Employee
958 Views
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.
0 Kudos
Reply