[Dev-C++] Linking DevCpp/MinGw with Compaq Fortran DLL
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Matthew C. <Mat...@ne...> - 2005-06-22 16:13:11
|
Hi,
I am trying to call a Compaq Fortran DLL written by a colleague from a MinGW C++
application in DevCpp. I added the *.lib file from the DLL to the libraries on the
DevCpp project. I can get a simple program(pasted below) to link, start, and work with
a test function in the DLL which adds integer arguments. A more complex function which
fills an initially empty array fails-the array comes back as all zeros. The Fortran
DLL prints the array as it is filling it, so the function seems to be called and there
are numbers going into the array in Fortran. However, when the returned array is
printed from C++ it is still all zeros. The C++ code is attached below. I have tried
using __stdcall in place of the "extern C" calling, however, this leads to linker
errors between the DLL and DevCpp, even if the DLL is recompiled with __stdcall,
making me wonder if there is some special trick for mixing Compaq Fortran and MinGW?
Thanks for any ideas or pointers,
Matt
/*
This program works with a FORTRAN *.DLL with the *.lib files for compile-time
checking of links*/
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <iomanip>
using std::cout;
using std::endl;
extern "C" void ADD2(int* a, int* b, int* c, int* d, int* e);
extern "C" void arraytest(double* array);
int main(int argc, char *argv[])
{
int a,b,c,d,e;
a=4;
b=9;
c=0;
d=0;
e=0;
ADD2(&a,&b,&c, &d, &e);
cout << "Testing Addition DLL" << endl;
cout << a << " " << b << " " << c << " " << d << " " << e << endl;
cout << "Testing Array DLL" << endl;
double dTest[7];
for (int nKount=0; nKount<7; nKount++) dTest[nKount] = 0;
arraytest(dTest);
int nKount, nKount2;
cout << "Array is" << endl;
for (nKount = 0; nKount < 7; nKount++)
{
cout << std::setw(5) << dTest[nKount] << " " << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
---------------------------------------------
Matthew Collette, Phd Student
MAST School Office, Armstrong Building
University of Newcastle
Newcastle upon Tyne
NE1 7RU, United Kingdom
Direct +44 (0)191 222 5534
|