Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28459 Discussions

LInking a Ftn DLL with a C static library

Richard_S_9
Beginner
1,912 Views

I am updating a 15 year old VB6 project that calls routines in a Ftn DLL. The DLL calls routines in a C++ static library. I have recently purchased the Intel Fortran compiler and have downloaded Visual Studio 2016. I have converted all of the VB, Ftn and C code. I did this by defining three, separate, Visual Studio projects: PcbPrg, PcbDll and PcbStl, a VB Windows forms project, a Ftn DLL project and a C static library project. I have been successful in calling the Ftn DLL routines (after about a week in “DLL Hell”).

My one remaining problem is getting the Ftn DLL routines to find/recognize the C static library. I have spent another week or longer reviewing the relevant information on the internet, including Steve Lionel’s discussions, including the one on August 10,2015, with other users having similar problems. I have also downloaded the Intel Reference Guide(2600 pages) and got a little bit lost and discouraged in that impressive document.

So here is a code snippet that shows where I am. Ignore the unusual line spacing and the occasional red colored underlines which evidently result from copying from MS Word. 

************************************************************************

      subroutine BITMAP_SIZE(bmpfile, bmpwidth, bmpheight, bmperror)

************************************************************************

      implicit real*8 (a-h,o-z)

 

      !DEC$  ATTRIBUTES DLLEXPORT :: BITMAP_SIZE

      !DEC$  ATTRIBUTES ALIAS: 'BITMAP_SIZE' :: BITMAP_SIZE

 

      interface

         subroutine BmpSize(bmpfile,bmpwidth,bmpheight,bmperror)

            !dec$ attributes C, alias:'BmpSize' :: BmpSize            

            !character (len=*) bmpfile

            integer bmpwidth,bmpheight,bmperror

            !dec$ attributes reference :: bmpfile

            !dec$ attributes reference :: bmpwidth

            !dec$ attributes reference :: bmpheight

            !dec$ attributes reference :: bmperror

         end subroutine BmpSize

      end interface

 

      character (len=*) bmpfile

      integer bmpwidth, bmpheight, bmperror

     

      bmperror=0

 

      call BmpSize(bmpfile,bmpwidth,bmpheight,bmperror)

 

       return

 

       end

 

 

 

 

The VB calling routine successfully locates the Ftn called routine, BITMAP_SIZE, but throws an exception at the call to the C static library procedure, BmpSize,

 

      call BmpSize(bmpfile,bmpwidth,bmpheight,bmperror)

 

 

 

The error message is,

 

error LNK2001: unresolved external symbol BmpSize

I guess this is not surprising, since I haven’t indicated, in the Visual Studio IDE for the Ftn project, where to find the C static library.

How do I do that?

I might add that I have an analogous problem trying to tie the VB project to the Ftn DLL project, using the IDE. I have taken the easy way out by putting the Ftn DLL file in the same folder as the VB exe file. This works fine but I am not able to run from within the IDE in either the debug or release configuration.

Finally, let me compliment Intel on the ease and efficiency with which your compiler ate up my old, fixed format, Fortran code and spit it out beautifully. I’ve probably gotten my $850 worth already, but if we can just get the DLL and the static library talking to each other, I would be doubly  happy.

 

Thanks in advance,

Richard Sampson

0 Kudos
21 Replies
Steven_L_Intel1
Employee
225 Views

Richard, glad to hear you have it sorted out.

The samples are installed in the Parallel Studio XE installation folder. There are several levels of subfolder to wade through, but the direct link on my system is C:\Program Files (x86)\IntelSWTools\samples_2016\en\compiler_f\psxe  These are ZIP files that you must unzip to a writable folder, such as your Desktop or your projects folder.

0 Kudos
Reply