In a DLL project, we export all our subroutines and functions (which are normally in modules) using:
!dec$ attributes dllexport :: routine_name
in the appropriate place in the files.
I now want to add some external code which I'd rather not edit (as it will get overwritten every time I get new versions), so I created a DEF file containing:
Then I included this file in the DLL project and rebuilt. However when I look in the DLL using DEPENDS, these functions are not exported.
Not sure what I am doing wrong.
It is very likely that you don't need to specify the ordinal (you would only need it if procedures in the DLL were being referenced by that ordinal - rare for user code) - you can just list the name of the procedure to be exported.
But some experimentation here shows that it doesn't appear to prevent the symbol being exported by name anyway.
! apple.f90 SUBROUTINE apple() BIND(C, NAME='apple') IMPLICIT NONE END SUBROUTINE apple
! banana.f90 MODULE m IMPLICIT NONE CONTAINS SUBROUTINE banana !DEC$ ATTRIBUTES DLLEXPORT :: banana END SUBROUTINE banana END MODULE m
; dll.def EXPORTS apple @1
>ifort /dll "2018-05-24 apple.f90" "2018-05-24 banana.f90" "2018-05-24 dll.def" /exe:"2018-05-24 dll.dll" Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 188.8.131.52 Build 20180210 Copyright (C) 1985-2018 Intel Corporation. All rights reserved. Microsoft (R) Incremental Linker Version 14.00.24215.1 Copyright (C) Microsoft Corporation. All rights reserved. "-out:2018-05-24 dll.dll" -dll "-implib:2018-05-24 dll.lib" "-def:2018-05-24 dll.def" "2018-05-24 apple.obj" "2018-05-24 banana.obj" Creating library 2018-05-24 dll.lib and object 2018-05-24 dll.exp >dumpbin /exports "2018-05-24 dll.dll" Microsoft (R) COFF/PE Dumper Version 14.00.24215.1 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file 2018-05-24 dll.dll File Type: DLL Section contains the following exports for 2018-05-24 dll.dll 00000000 characteristics 5B069BD9 time date stamp Thu May 24 20:32:49 2018 0.00 version 1 ordinal base 2 number of functions 2 number of names ordinal hint RVA name 2 0 00001020 M_mp_BANANA 1 1 00001000 apple
I removed the ordinals, rebuilt the project, but the routines in the DEF file do not appear in the dumpbin. Only the ones which have explicit "!dec$ attributes dllexport :: " appear.
I see the problem. When I simply add the DEF file to the project in VS (like I add a F90 file) it does not add it to the LINK command line as you have manually done in your example. I have to physically specify it as a "Module Definition File". Then it adds it to the LINK command line as /DEF:file.def which works.
With the def file from above changed to:
; dll.def EXPORTS apple @1 NONAME
if I relink I see the exports as:
>dumpbin /exports "2018-05-24 dll.dll" ... Section contains the following exports for 2018-05-24 dll.dll 00000000 characteristics 5B07198A time date stamp Fri May 25 05:29:06 2018 0.00 version 1 ordinal base 2 number of functions 1 number of names ordinal hint RVA name 2 0 00001020 M_mp_BANANA 1 00001000 [NONAME]
But I don't recommend excluding the names and/or linking by ordinal.
Why do you not recommend excluding the names and/or linking by ordinal ?
Say for example you are distributing a product where your code exists in 1 exe and number of DLL's and you and you only want to call that DLL from your code. Hiding that name would prevent someone else from using your DLL for their own purposes.
They are not stopped from calling the code in the DLL, they just don't have a name for the entry point.
Ordinals are a hangover from 16 bit days when bytes mattered. Named exports are easier to maintain.