Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

Problem with linking DLL

$
0
0

I am trying to turn a series of sub-routines of a code into a DLL. It's the first time I do that so I'm a newbie and this is probably a trivial question. The original code compiles and runs without problems. I made a new project with the routines, it also compiled without problems. The problem arises when compiling the main program, with the LIB included.

This is the main code, where I explicitly import a routine from the DLL, and USE a module from the DLL:

program nts

use IDFCOM

!DEC$ ATTRIBUTES DLLIMPORT::calc_n

implicit none

call calc_n

write(*,*)'n:',n

end program

 

This is the DLL:

 

module IDFCOM

!DEC$ ATTRIBUTES DLLEXPORT::n

integer,allocatable::n(:)

end module IDFCOM

 

subroutine calc_n

!DEC$ ATTRIBUTES DLLEXPORT::calc_n

use IDFCOM

implicit none

allocate(n(2))

n(1)=1

n(2)=3

return

end subroutine

 

And this is the error I get when compiling:

error LNK2019: unresolved external symbol _IDFCOM_mp_N referenced in function _MAIN__

The documentation says "When a module is used in other program units, through the Use statement, any objects in the module with the DLLEXPORT property are treated in the program using the module as if they were declared with the DLLIMPORT property. So, a main program that uses a module contained in a DLL has the correct import attributes for all objects exported from the DLL."

So why can't I access the variable n, which has the DLLEXPORT attribute in the DLL, in the main routine?  The compiler does not complain about the subroutine, only about the data.

In the real code "n" is a series of allocatable derived variables. I don't know a priori how large they need to be, that's why I am transmitting them via the module.

Thanks!


Viewing all articles
Browse latest Browse all 5691

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>