Trouble linking FORTRAN DLL with C++ application (undefined reference) 
Author Message
 Trouble linking FORTRAN DLL with C++ application (undefined reference)

I created a fortran DLL with Digital Visual Fortran 6.0 and have been
able to access that DLL successfully from a calling application in
FORTRAN.

I'm now trying to call the same FORTRAN DLL from C++ and am having
trouble with the getting the calling conventions right.  I have
reviewed some relevant articles in comp.lang.fortran and in the Intel
developer forum, including these:

http://www.*-*-*.com/ %249ej%40usenet.pa.dec.com...

http://www.*-*-*.com/ %24kef4q%241%40ID-106075.n...

http://www.*-*-*.com/

Based on those and other articles, here's how I set things up.

(1) FORTRAN DLL source code:

Subroutine FORTRANINIT(int1,int2)
!
!
!DEC$ ATTRIBUTES DLLEXPORT::FORTRANINIT

INTEGER*4 int1, int2

(2) Calling C++ program source code:

extern "C"
  {
      __declspec(dllimport) void __stdcall FORTRANINIT(int* int1,
            int* int2);
  }

  void main()
  {
        int int1, int2;

   <snip>

        FORTRANINIT(&int1, &int1);
  }

(3) Building/compiling:

(a) I built FORTRANINIT.dll first (in DVF 6.0) and copied it to the
    C++ application's directory.

(b) I added the FORTRANINIT.lib file to the C++ project in {*filter*}shed
    Dev-C++ 4.0 (from www.{*filter*}shed.net/devcpp.html) and compiled the
    calling C++ application.

(c) There were no compilation errors, but there was a linker error:


Any ideas as to what I'm missing here?  I would like to be able to
call the same FORTRAN DLL from FORTRAN and C++.  I have tried
omitting both the FORTRAN ALIAS as well as the __declspec(dllimport)
in C++ without any luck.

Thanks in advance for the help!

 - Steve Kramer



Sun, 16 Jul 2006 09:16:06 GMT  
 Trouble linking FORTRAN DLL with C++ application (undefined reference)
| I created a FORTRAN DLL with Digital Visual Fortran 6.0 and have been
| able to access that DLL successfully from a calling application in
| FORTRAN.
|
| I'm now trying to call the same FORTRAN DLL from C++ and am having
| trouble with the getting the calling conventions right.  I have
| reviewed some relevant articles in comp.lang.fortran and in the Intel
| developer forum, including these:
|
<snip>
| Based on those and other articles, here's how I set things up.
|
<snip>
| (b) I added the FORTRANINIT.lib file to the C++ project in {*filter*}shed
|     Dev-C++ 4.0 (from www.{*filter*}shed.net/devcpp.html) and compiled the
|     calling C++ application.
|
| (c) There were no compilation errors, but there was a linker error:
|

|
| Any ideas as to what I'm missing here?  I would like to be able to
| call the same FORTRAN DLL from FORTRAN and C++.  I have tried
| omitting both the FORTRAN ALIAS as well as the __declspec(dllimport)
| in C++ without any luck.

It seems you followed a correct procedure... for linking with Visual C++.

I suspect the problem is that you're using Dev-C++, and I don't know
if it's link-compatible with MSVC++/CVF. Based on the info from web site
you provided, it seems not (it says that its compiler is Mingw port of
gcc).

You'd be probably better off asking this in a Devcpp/mingw/gcc specific
group. The issue is the same as how to call a dll written in VC++ from
that environment (as CVF .dlls and .libs are the same as VC++ looking
from outside).

--
 Jugoslav
___________
www.geocities.com/jdujic



Sun, 16 Jul 2006 16:48:05 GMT  
 Trouble linking FORTRAN DLL with C++ application (undefined reference)


Wed, 18 Jun 1902 08:00:00 GMT  
 Trouble linking FORTRAN DLL with C++ application (undefined reference)
...

Quote:

> It seems you followed a correct procedure... for linking with Visual C++.

> I suspect the problem is that you're using Dev-C++, and I don't know
> if it's link-compatible with MSVC++/CVF. Based on the info from web site
> you provided, it seems not (it says that its compiler is Mingw port of
> gcc).

> You'd be probably better off asking this in a Devcpp/mingw/gcc specific
> group. The issue is the same as how to call a dll written in VC++ from
> that environment (as CVF .dlls and .libs are the same as VC++ looking
> from outside).

Dujic, you had a great suggestion.  I did some further searching and
found that devcpp/mingw/gcc is not binary-compatible with Microsoft
COFF-format libraries.  I switched to using Borland C++Builder, which
also is not compatible with Microsoft's format, but there is a way to
convert from the COFF format to Borland's OMF format.  I followed the
directions given by Harold Howe
(http://www.bcbdev.com/articles/vcdll.htm), and now I'm able to use my
DVF DLLs from Borland C++Builder.  Thanks, Harold and Jugoslav, for
your help!

 - Steve



Tue, 18 Jul 2006 13:22:12 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. cannot link dll : undefined reference to `tclStubsPtr'

2. troubles with fortran/c++ mixed linking.

3. Statically linking a Fortran .lib into a C++ .dll

4. Unresolved External error when linking a Fortran Dll from C++

5. LINK Undefined Reference to WIN32 binding using GNAT 3.13

6. linking with shared library, undefined reference to Py_BuildValue

7. some undefined references in tclLoadDl.o (dlopen, dlsym) while linking with libtcl7.6a

8. Fortran 95 Link Error: Undefined symbol

9. Linking FORTRAN Routine to C++ Program, MS C++ DVF Library Problem

10. C,C++,Fortran - f77argc and f77argv undefined, why?

11. Link a C++ DLL to Clarion 4b Program

12. C++ .dll linked in XBase++ .exe

 

 
Powered by phpBB® Forum Software