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

How create a dynamic library from multiple files...

Javier_Gonzalez-plat
1,434 Views

Hi!

The question is easy, how can I create a dll library from several fortran files?

Javier

0 Kudos
8 Replies
Arjen_Markus
Honored Contributor I
1,434 Views

The answer is equally easy: in the same way you would a standalone program.

If you use Visual Studio, define a project with the required output type. If you use the command-line, then:

ifort /dll name1.obj name2.obj name3.obj ... /exe:dllname.dll

(assuming you have already compiled the individual source files)

0 Kudos
Javier_Gonzalez-plat
1,434 Views

OK Thanks,

But reading the documentation say that I should have to files. One is the dll file and the second is a lib file in order to use to link when I have to do a program.

The previous procedure create the dll file, but where is the lib file?

Thanks again

0 Kudos
Steve_Lionel
Honored Contributor III
1,434 Views

The .lib is created in the same place as the DLL. If you don't see it, then you're missing !DEC$ ATTRIBUTES DLLEXPORT directives for any routines you want exported from the DLL.

0 Kudos
Javier_Gonzalez-plat
1,434 Views

Hello

When I do a static library, I need only the mod and smod files and the lib file to create a new program. I don't need worry about which routines I'm using in the program.

Now, I'm trying to do the same but using dll. I don't understand when you say that I need !DEC$ ATTRIBUTES DLLEXPORT if I want to export any routines from DLL. From your comment, I have to add !..... (macro) in every procedure (subroutine or function)? inclusive if I use modules or submodules?

Javier

 

 

0 Kudos
Steve_Lionel
Honored Contributor III
1,434 Views

You need to add an ATTRIBUTES DLLEXPORT directive in each and every subroutine and function you want visible outside the DLL. It goes in the actual routine, not interfaces. For example:

subroutine foobar (arg1, arg2)
!DEC$ ATTRIBUTES DLLEXPORT :: foobar
...

You're right that this is different from creating a static library. When using it, it's the same - link to the .lib. (Of course, you then have to make sure the DLL is in a location Windows will find it.)

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,434 Views

Only the subroutines and functions (optionally data) that are required to be called from the users of your DLL require the !DEC$ ATTRIBUTES DLLEXPORT ... The DLL private procedures need not have the DLLEXPORT.

See: https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-attributes-dllexport-and-dllimport

Jim Dempsey

0 Kudos
Javier_Gonzalez-plat
1,434 Views

OK

My last question. All my procedures (functions or subroutines) are into a modules (or submodules). For each modules I have private and public procedures and variables.

If I understand well, I need to put in each public variables and public procedures the directive !DEC$ ATTRIBUTES....., right?

Is not possible to write all directives in one zone of the module file?

and I have seen also !DIR$ ATTRIBUTES DLL.....  what is the difference respect to !DEC$ ATTRIBUTES DLL....?

Thanks for your help.

 

Javier

 

0 Kudos
Steve_Lionel
Honored Contributor III
1,434 Views

You cannot put these in the module interface - they must go in the actual procedure. When you put a DLLEXPORT into a module procedure, it turns into a DLLIMPORT when the module is USEd.

There is no difference between !DEC$ and !DIR$. Either prefix works.

0 Kudos
Reply