Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
2 Views

Compiling fortran program with HECDSS routines in a third party library

I can successfully compile a simple fortran program within the Visual Studio shell that magically accesses to HECDSS utilities, e.g., ZSET, in a library or dll.  Anybody know how to do it from the command line, i.e., without VS?  I've added "*DEC$ ATTRIBUTES DLLIMPORT:: ZSET" to my code, as shown below, but the compiler doesn't like it, it seems - see the compiler output to the screen shown below my mini program below.

! Simplified code to test reachability of DSS routines

      PROGRAM DH_DSS_UTILITY

*DEC$ ATTRIBUTES DLLIMPORT:: ZSET

      CHARACTER*640 cdssECin
      CHARACTER*640 cdssECout
      LOGICAL       ldssECin

      ldssECin = .FALSE.
      CALL ZSET('MLEVEL', ' ',0) ! Set the error messaging level 0 = minimum - only abort messages
      DO i = 1, 640
        cdssECin(i:i) = ' '
        cdssECout(i:i) = ' '
      ENDDO
      STOP

      END PROGRAM DH_DSS_UTILITY

---------------------------------------------------------------------------------------------------


Attempts to compile the program with HECDSS' ZSET routine.
---------------------------------------------------------


c:\4DSIBMtesting>ifort DSSsource2.f heclib.lib
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.7.272 Build 20180408
Copyright (C) 1985-2018 Intel Corporation.  All rights reserved.
Microsoft (R) Incremental Linker Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:DSSsource2.exe
-subsystem:console
DSSsource2.obj
heclib.lib
DSSsource2.obj : error LNK2019: unresolved external symbol __imp_ZSET referenced in function MAIN__
DSSsource2.exe : fatal error LNK1120: 1 unresolved externals


c:\4DSIBMtesting>ifort /libs:dll DSSsource2.f heclib_x64.dll
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.7.272 Build 20180408
Copyright (C) 1985-2018 Intel Corporation.  All rights reserved.
ifort: command line warning #10161: unrecognized source type 'heclib_x64.dll'; object file assumed
ipo: warning #11010: file format not recognized for c:\4DSIBMtesting\heclib_x64.dll
Microsoft (R) Incremental Linker Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:DSSsource2.exe
-subsystem:console
DSSsource2.obj
heclib_x64.dll
heclib_x64.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x338
 

Any ideas what I'm missing?

0 Kudos
11 Replies
Highlighted
Black Belt
2 Views

The compiler likes your code

The compiler likes your code just fine. The issue is whether the heclib.lib you are linking to is a DLL export library that exports ZSET.

Do this from the command line:

dumpbin -exports heclib.lib

Do you see ZSET (spelled exactly that way in upper case) in the output?

Your second ifort command is incorrect as one does not link to a DLL.

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Beginner
2 Views

Thank you, thank you, thank

Thank you, thank you, thank you for your prompt, responsive reply!

dumpbin -exports heclib.lib produced the following - 

Dump of file heclib.lib

File Type: LIBRARY

  Summary

       40174 .bss
       2E7F8 .data
         300 .debug$F
       BABC0 .debug$S
       2E41C .debug$T
        FA6D .drectve
       18927 .rdata
       96496 .text
        E2C8 .trace

I suspect those are akin to directories and that the HECDSS routines might be within one???

I have another source - a DLL that I thought might have the HECDSS routines I am looking for, so I typed

"dumpbin -exports heclib_x64.dll"

Here's what I got -

Microsoft (R) COFF/PE Dumper Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file heclib_x64.dll

File Type: DLL

  Section contains the following exports for HECLIB.dll

    00000000 characteristics
    526EB354 time date stamp Mon Oct 28 11:56:20 2013
        0.00 version
           1 ordinal base
          62 number of functions
          62 number of names

    ordinal hint RVA      name

          1    0 00003150 ADDONE_
          2    1 000037D0 CHRHOL_
          . . . 
         52   33 00003270 ZSET_

         . . . 

         62   3D 00003AE0 ZWRITX_

  Summary

       90000 .data
        2000 .pdata
        8000 .rdata
        1000 .reloc
        1000 .rsrc
       4E000 .text
        2000 _RDATA
 

Should I rename my FORTRAN program's routine's name from ZSET to ZSET_ ?

FYI, I previously tried "ifort /libs:dll DSSsource3.f heclib_x64.dll" but got the following

c:\4DSIBMtesting>ifort /libs:dll DSSsource3.f heclib_x64.dll
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.7.272 Build 20180408
Copyright (C) 1985-2018 Intel Corporation.  All rights reserved.
ifort: command line warning #10161: unrecognized source type 'heclib_x64.dll'; object file assumed

ipo: warning #11010: file format not recognized for c:\4DSIBMtesting\heclib_x64.dll
Microsoft (R) Incremental Linker Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:DSSsource3.exe
-subsystem:console
DSSsource3.obj
heclib_x64.dll
heclib_x64.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x338
 

Thanks in advance for whatever additional help you may be able to provide.

0 Kudos
Highlighted
Beginner
2 Views

Sorry Steve, you already told

Sorry Steve, you already told me my I couldn't do "ifort /libs:dll DSSsource3.f heclib_x64.dll"

Based on the fact dumpbin listing shows the HECDSS routines I want to use, albeit with a trailing underscore, I'm wondering if I can somehow integrate that DLL in the complilation.

 

0 Kudos
Highlighted
Black Belt
2 Views

No, you can't integrate the

No, you can't integrate the DLL in your build.

My guess is that the particular library you're using from the command line is a static library, and that the DLL import library is somewhere else. Show the output of this command:

dumpbin -symbols heclib.lib

If you see ZSET in there, just take out the *DEC$ ATTRIBUTES line from your source.  This line is optional (though recommended) if calling an entry point in a DLL - omitting it when using a DLL simply adds a couple of instructions to the call. (ATTRIBUTES DLLIMPORT is required if you are referencing a variable or COMMON block in the DLL.)

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Beginner
2 Views

Here's the output from

Here's the output from dumpbin -symbols heclib.lib (I deleted lots of stuff seemingly related to other utilities in heclib.lib)

Microsoft (R) COFF/PE Dumper Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file heclib.lib

File Type: LIBRARY

. . .

COFF SYMBOL TABLE
000 0000005D DEBUG  notype       Filename     | .file       J:\heclib\heclib\Dss\zset.for
003 00000001 ABS    notype       Static       | @feat.00
004 00000000 SECT1  notype       Static       | .rdata        Section length  2FC, #relocs    0, #linenums    0, checksum        0
006 00000000 SECT1  notype       Static       | STRLITPACK_75
007 00000008 SECT1  notype       Static       | STRLITPACK_74
. . .
04C 000001D4 SECT1  notype       Static       | STRLITPACK_61
04D 000001D8 SECT1  notype       Static       | STRLITPACK_63
04E 00000000 SECT2  notype       Static       | .text       Section length 2484, #relocs  252, #linenums    0, checksum        0
050 00000020 UNDEF  notype       External     | _zstatus_
051 00000010 UNDEF  notype       External     | _zdssrz_
052 000005C0 UNDEF  notype       External     | _zdssiz_
053 00000CE0 UNDEF  notype       External     | _zdsscz_
054 00000030 UNDEF  notype       External     | _zdsstzc_
055 00000010 UNDEF  notype       External     | _zdsstzi_
056 00000020 UNDEF  notype       External     | _zdsscm_
057 00000010 UNDEF  notype       External     | _dcdbug_
058 000000A0 UNDEF  notype       External     | _zdssnz_
059 00000080 UNDEF  notype       External     | _zdsslz_
05A 000000A0 UNDEF  notype       External     | _zdssmz_
05B 00000010 UNDEF  notype       External     | _zdssfz_
05C 00000000 UNDEF  notype       External     | __fltused
05D 00000000 DEBUG  notype       Filename     | .file       J:\heclib\heclib\Dss\zset.for
060 00000000 SECT2  notype ()    External     | _zset_      tag index 00000062 size 00002484 lines 00000000 next function 00000000
062 00000000 SECT2  notype       BeginFunction | .bf        line# 0001 end 00000000
064 00000000 SECT2  notype       .bf or.ef    | .lf
065 00002484 SECT2  notype       EndFunction  | .ef         line# 0164
067 00000000 UNDEF  notype ()    External     | _zinit_
068 00000000 SECT3  notype       Static       | .bss        Section length    8, #relocs    0, #linenums    0, checksum        0
06A 00000000 UNDEF  notype ()    External     | _for_cpystr
06B 00000000 SECT4  notype       Static       | .data       Section length  100, #relocs    0, #linenums    0, checksum        0
06D 00000000 UNDEF  notype ()    External     | _for_write_seq_fmt
06E 00000000 UNDEF  notype ()    External     | _for_write_seq_fmt_xmit
06F 0000020C SECT1  notype       Static       | _2il0floatpacket.1
070 00000000 UNDEF  notype ()    External     | ___powr4i4
071 00000210 SECT1  notype       Static       | _2il0floatpacket.2
072 00000000 UNDEF  notype ()    External     | _for_cpstr
073 00000000 UNDEF  notype ()    External     | _upcase_
074 00000000 SECT3  notype       Static       | zset_$CFLAG
075 00000004 SECT3  notype       Static       | zset_$CSTRIN
076 00000000 SECT4  notype       Static       | zset_$BLK$format_pack
077 000001DC SECT1  notype       Static       | STRLITPACK_87
078 000001E4 SECT1  notype       Static       | STRLITPACK_88
079 000001EC SECT1  notype       Static       | STRLITPACK_89
07A 000001F4 SECT1  notype       Static       | STRLITPACK_90
07B 000001FC SECT1  notype       Static       | STRLITPACK_91
07C 00000204 SECT1  notype       Static       | STRLITPACK_92
07D 00000000 SECT5  notype       Static       | .debug$S    Section length 1C64, #relocs  1F6, #linenums    0, checksum        0
07F 00000000 SECT8  notype       Static       | .debug$T    Section length  45C, #relocs    0, #linenums    0, checksum        0
081 000001E0 UNDEF  notype       External     | _zdsskz_
082 00013880 UNDEF  notype       External     | _zdssts_
083 000007E0 UNDEF  notype       External     | _zdssti_
084 00000214 SECT1  notype       Static       | STRLITPACK_0
085 00000220 SECT1  notype       Static       | STRLITPACK_1
086 0000022C SECT1  notype       Static       | STRLITPACK_2
087 00000234 SECT1  notype       Static       | STRLITPACK_3
088 0000025C SECT1  notype       Static       | STRLITPACK_76
089 00000268 SECT1  notype       Static       | STRLITPACK_77
08A 00000274 SECT1  notype       Static       | STRLITPACK_78
08B 0000029C SECT1  notype       Static       | STRLITPACK_79
08C 000002A8 SECT1  notype       Static       | STRLITPACK_80
08D 000002B4 SECT1  notype       Static       | STRLITPACK_81
08E 000002C0 SECT1  notype       Static       | STRLITPACK_82
08F 000002CC SECT1  notype       Static       | STRLITPACK_83
090 000002D8 SECT1  notype       Static       | STRLITPACK_84
091 000002E4 SECT1  notype       Static       | STRLITPACK_85
092 000002F0 SECT1  notype       Static       | STRLITPACK_86
093 00000000 SECT6  notype       Static       | .drectve    Section length   B8, #relocs    0, #linenums    0, checksum        0
095 00000000 SECT7  notype       Static       | .trace      Section length  1E8, #relocs    2, #linenums    0, checksum        0

String Table Size = 0x5DA bytes

. . . 

  Summary

       40174 .bss
       2E7F8 .data
         300 .debug$F
       BABC0 .debug$S
       2E41C .debug$T
        FA6D .drectve
       18927 .rdata
       96496 .text
        E2C8 .trace
 

0 Kudos
Highlighted
Black Belt
2 Views

Ok, this tells me a few

Ok, this tells me a few things. First, it's a 32-bit static library and you're building using the 64-bit compiler. You need to find the 64-bit library.

Second, it was compiled with conventions used by gfortran and some other U*X compilers in that the names are lowercase and have an underscore on the end, neither of which are the defaults in Intel Fortran on Windows.

Once you find the 64-bit library. add this line to your program source:

!DEC$ ATTRIBUTES DECORATE, ALIAS:"zset_" :: ZSET

But before you do that, do the dumpbin -symbols on the 64-bit library and make sure that the line similar to:

SECT2  notype ()    External     | _zset_    

has the name as zset_ without the leading underscore. Your Visual Studio project has some non-default settings that adjust for the name differences, but I don't recommend using them.

 

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Beginner
2 Views

Steve,

Steve,

Are you able to tell if there is a way to access ZSET from the dumpbin -symbols heclib.lib output?

When I took out the *DEC$ ATTRIBUTES statement, I'm back to the compiler error statement:

" error LNK2019: unresolved external symbol ZSET referenced in function MAIN__"

FYI, the heclib.lib and heclib_x64.dll are in the same folder as the source code.

I've assumed it doesn't matter that Windows Explorer on my Windows 10 machine lists heclib as having the Type "VisualStudio.lib.31d2e686"

Thanks in advance for any help you may be able to provide.

Derek

0 Kudos
Highlighted
Black Belt
2 Views

A couple more things.

A couple more things.

Looking back at the dump you did of the DLL tells me that the x64 DLL doesn't use lowercase names but does use a trailing underscore. So you first need to find the .lib corresponding to the x64 DLL, and then use:

!DEC$ ATTRIBUTES DECORATE, ALIAS:"ZSET_" :: ZSET

in your program.

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Beginner
2 Views

Okay, I have a 64bit version

Okay, I have a 64bit version of the HEC DSS library.  I ran dumpbin -symbols on it. See below.  Believing it was good to go, I tried to compile the program with the compiler declaration you suggested (code follows the dumpbin info below).  Below the code is what the compiler printed out to the screen.  Any additional insight you may be able to provide would be much appreciated?

 

Microsoft (R) COFF/PE Dumper Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file heclib.lib

File Type: LIBRARY

[ Several "COEFF SYMBOL TABLE" removed ]

COFF SYMBOL TABLE
000 00000000 DEBUG  notype       Filename     | .file
    dss\zset.f
002 00000000 SECT1  notype       Static       | .text
    Section length 1040, #relocs   CA, #linenums    0, checksum        0
004 00000000 SECT1  notype ()    External     | zset_
005 00000020 UNDEF  notype       External     | zstatus_
006 00000010 UNDEF  notype       External     | zdssrz_
007 00000CE0 UNDEF  notype       External     | zdsscz_
008 00000030 UNDEF  notype       External     | zdsstzc_
009 00000010 UNDEF  notype       External     | zdsstzi_
00A 00000020 UNDEF  notype       External     | zdsscm_
00B 00000010 UNDEF  notype       External     | dcdbug_
00C 000000A0 UNDEF  notype       External     | zdssnz_
00D 00000080 UNDEF  notype       External     | zdsslz_
00E 000005C0 UNDEF  notype       External     | zdssiz_
00F 000000A0 UNDEF  notype       External     | zdssmz_
010 00000010 UNDEF  notype       External     | zdssfz_
011 00000000 SECT2  notype       Static       | .bss
    Section length    8, #relocs    0, #linenums    0, checksum        0
013 00000000 UNDEF  notype ()    External     | for_cpystr
014 00000000 SECT3  notype       Static       | .rdata
    Section length   80, #relocs    0, #linenums    0, checksum        0
016 00000030 SECT3  notype       Static       | _2_STRLITPACK_5
017 00000034 SECT3  notype       Static       | _2_STRLITPACK_4
018 00000038 SECT3  notype       Static       | _2_STRLITPACK_7
019 0000003C SECT3  notype       Static       | _2_STRLITPACK_9
01A 00000040 SECT3  notype       Static       | _2_STRLITPACK_11
01B 00000044 SECT3  notype       Static       | _2_STRLITPACK_13
01C 00000048 SECT3  notype       Static       | _2_STRLITPACK_15
01D 0000004C SECT3  notype       Static       | _2_STRLITPACK_19
01E 00000050 SECT3  notype       Static       | _2_STRLITPACK_23
01F 00000054 SECT3  notype       Static       | _2_STRLITPACK_25
020 00000058 SECT3  notype       Static       | _2_STRLITPACK_27
021 0000005C SECT3  notype       Static       | _2_STRLITPACK_29
022 00000060 SECT3  notype       Static       | _2_STRLITPACK_31
023 00000064 SECT3  notype       Static       | _2_STRLITPACK_33
024 00000068 SECT3  notype       Static       | _2_STRLITPACK_35
025 0000006C SECT3  notype       Static       | _2_STRLITPACK_54
026 00000070 SECT3  notype       Static       | _2_STRLITPACK_58
027 00000074 SECT3  notype       Static       | _2_STRLITPACK_60
028 00000078 SECT3  notype       Static       | _2il0floatpacket.5
029 0000007C SECT3  notype       Static       | _2il0floatpacket.6
02A 00000000 SECT4  notype       Static       | .data
    Section length  100, #relocs    0, #linenums    0, checksum        0
02C 00000000 UNDEF  notype ()    External     | for_write_seq_fmt
02D 00000000 UNDEF  notype ()    External     | for_write_seq_fmt_xmit
02E 00000000 UNDEF  notype ()    External     | __powr4i4
02F 00000000 UNDEF  notype ()    External     | for_cpstr
030 00000000 UNDEF  notype ()    External     | upcase_
031 00000000 UNDEF  notype ()    External     | zinit_
032 00000000 SECT5  notype       Static       | .xdata
    Section length   10, #relocs    0, #linenums    0, checksum        0
034 00000000 SECT6  notype       Static       | .pdata
    Section length    C, #relocs    3, #linenums    0, checksum        0
036 00000000 SECT2  notype       Static       | zset_$CFLAG.0.1
037 00000004 SECT2  notype       Static       | zset_$CSTRIN.0.1
038 00000000 SECT4  notype       Static       | zset_$BLK$format_pack.0.1
039 000001E0 UNDEF  notype       External     | zdsskz_
03A 00061A80 UNDEF  notype       External     | zdssts_
03B 00000FA0 UNDEF  notype       External     | zdssti_
03C 00000000 UNDEF  notype ()    External     | __ImageBase
03D 00000000 UNDEF  notype       External     | _fltused
03E 00000000 SECT7  notype       Static       | .drectve
    Section length   B7, #relocs    0, #linenums    0, checksum        0

String Table Size = 0x1E7 bytes

[ Several "COEFF SYMBOL TABLE" removed ]

  Summary

       3B7C0 .bss
       2E44C .data
        1528 .debug$S
       1043D .drectve
        1ED8 .pdata
        86CD .rdata
       85140 .text
        2F78 .xdata

---------------------------------------------------------------------------

Program source code:

      PROGRAM DSSsource5

*DEC$ ATTRIBUTES DECORATE, ALIAS:"zset_"::ZSET
! *DEC$ ATTRIBUTES STDCALL, REFERENCE:: ZSET
! *DEC$ ATTRIBUTES DLLIMPORT:: ZSET

      CHARACTER*640 cdssECin
      CHARACTER*640 cdssECout
      LOGICAL       ldssECin

      ldssECin = .FALSE.
      CALL ZSET('MLEVEL', ' ',0) ! Set the error messaging level
      DO i = 1, 640
        cdssECin(i:i) = ' '
        cdssECout(i:i) = ' '
      ENDDO
      STOP

      END PROGRAM DSSsource5

---------------------------------------------------------------------------

Compiler message:

c:\4DSIBMtesting>ifort DSSsource5.f heclib.lib
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.7.272 Build 20180408
Copyright (C) 1985-2018 Intel Corporation.  All rights reserved.

DSSsource5.f(5): error #7794: Only a function or subroutine subprogram may have the DEC$ ATTRIBUTES directive DECORATE specifier.   [ZSET]
*DEC$ ATTRIBUTES DECORATE, ALIAS:"zset_"::ZSET
------------------------------------------^
compilation aborted for DSSsource5.f (code 1)

 

0 Kudos
Highlighted
Black Belt
2 Views

Take off the DECORATE

Take off the DECORATE attribute. You also don't need DLLIMPORT as this is a static library.

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Beginner
2 Views

The command line instruction

The command line instruction "ifort sourcecode.f heclib.lib" works perfectly now that I have an appropriate heclib.lib (i.e., 64bit)

AND I put the following statement atop my code:  *DEC$ ATTRIBUTES ALIAS:"zset_"::ZSET"

Thank you for your expertise, thank you for your patience, and thank you for your prompt, informative responses!

Problem solved.

 

0 Kudos