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

Getting the /version number

Simon_Geard
New Contributor I
730 Views

In the Linker>General part of a project's properties it is possible to set a version number using the /version option. Is it also possible to get this data programatically? How?

Thanks.


 

0 Kudos
4 Replies
Steven_L_Intel1
Employee
730 Views

You don't want to use that. Use the Version property in a resource file instead. You can read that using GetFileVersionInfo and VerQueryValue.

0 Kudos
Simon_Geard
New Contributor I
730 Views

Thanks I'll do that - I was just considering options.

0 Kudos
Steven_L_Intel1
Employee
730 Views

The /VERSION info can't be retrieved programmatically and isn't displayed normally. You could get it only with a dumpbin command. The resource property is the standard way to do this.

0 Kudos
IanH
Honored Contributor III
730 Views

I agree that the resource is a better way to go, so don't do this:

PROGRAM PrintExeHeaderVersion
  USE IFWIN, ONLY: HANDLE, GetModuleHandle, NULL, BYTE, WORD, DWORD
  
  !DEC$ IF DEFINED(_M_IX86)
  USE IFWIN, ONLY: T_IMAGE_NT_HEADERS => T_IMAGE_NT_HEADERS32
  !DEC$ ELSE IF DEFINED(_M_AMD64)
  USE IFWIN, ONLY: T_IMAGE_NT_HEADERS => T_IMAGE_NT_HEADERS64
  !DEC$ ENDIF
  
  USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_PTR, C_F_POINTER
  
  IMPLICIT NONE
  
  INTERFACE
    ! Get a pointer to the headers for the image file.  This is from the 
    ! ImageHlp library (you may need to link in ImageHlp.lib).
    FUNCTION ImageNtHeader(ImageBase)
      USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_PTR, C_INTPTR_T
      IMPLICIT NONE
      !-------------------------------------------------------------------------
      ! The headers define this as a pointer, but to be consistent with 
      ! a module handle, we make this a pointer sized integer.
      INTEGER(C_INTPTR_T), INTENT(IN) :: ImageBase
      !DEC$ ATTRIBUTES VALUE :: ImageBase
      TYPE(C_PTR) :: ImageNtHeader
      !DEC$ ATTRIBUTES STDCALL, DECORATE, ALIAS:'ImageNtHeader' :: ImageNtHeader
    END FUNCTION ImageNtHeader
  END INTERFACE
  
  ! The module handle for the executable for the current process.
  INTEGER(HANDLE) :: module_handle
  ! The C address of the headers for the image file.
  TYPE(C_PTR) :: headers_ptr
  ! The headers of the image file.
  TYPE(T_IMAGE_NT_HEADERS), POINTER :: headers
  
  !*****************************************************************************
  
  module_handle = GetModuleHandle(NULL)
  ! The module handle is also the base address of the module in memory!
  headers_ptr = ImageNtHeader(module_handle)
  CALL C_F_POINTER(headers_ptr, headers)
  
  PRINT "(I0,'.',I0)",  &
      headers%OptionalHeader%MajorImageVersion,  &
      headers%OptionalHeader%MinorImageVersion
END PROGRAM PrintExeHeaderVersion

 

>ifort /check:all /warn:all /standard-semantics PrintExeHeaderVersion.f90 /link /version:123.456 && PrintExeHeaderVersion.exe
Intel(R) Visual Fortran Compiler for applications running on IA-32, Version 16.0.0.110 Build 20150815
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:PrintExeHeaderVersion.exe
-subsystem:console
/version:123.456
PrintExeHeaderVersion.obj
123.456

(I think there's no harm in having the version in the resource file the same as the version in the executable header though - keeping them consistent may avoid confusion down the track.)

Edit: On further thought, that's just making a rod for your back.  Leave the executable header version as all zeros, i.e. clearly not in use.  There are enough issues with multiple concepts of version between individual files and msi type installations anyway, don't need to add another one.

0 Kudos
Reply