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

embed version info in shared object similar to resource file

Greg_T_
Valued Contributor I
917 Views

Hello, I'd like to embed version number information in a shared object (.so) binary during compiling and linking.  It looks like there is not a resource file available on Linux like on Windows with a version.rc resource file.  When building a DLL on Windows I can include a version.rc resource file and use the rc.exe resource compiler to get the version.res file to link into the DLL.  In the DLL properties/Details it gives the File Version number as 1.0.0.0 (similar discussion in: https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/281529 ).

Is there another approach used to embed version information for the shared object binary on Linux that can later be extracted by an external program?

I've seen that one convention on Linux is to append the version number to the .so file: libname.so.1.0.0

Perhaps I should add a few parameter statements in the Fortran to save the version numbers or string that could be accessed through an externally available routine to return the version information.

Thanks for your suggestions.
Greg T.

0 Kudos
3 Replies
Steven_L_Intel1
Employee
917 Views

As you have noted, Linux doesn't have anything like Windows' "resources" for executables and shared libraries. The usual approach on Linux is to declare a character variable at program or module scope that begins with a particular set of delimiters, such as starting with $version$ and ending with %, with the version number in the string. You'll want to use initialization in the declaration, such as:

CHARACTER(20) :: Version="$version$1.0.0$"//CHAR(0)

to make sure it gets into the object file intact. Then one normally uses the "strings" utility to search for the delimiters. The trailing NUL is needed as strings won't recognize it otherwise.

0 Kudos
Greg_T_
Valued Contributor I
917 Views

Steve, thank you for pointing me to the Linux strings utility and for providing an example of the needed syntax.  Since our Fortran code is used to build DLLs on Windows and .so shared objects on Linux I try it on both platforms.  After more reading it looks like Windows does not have an equivalent to the "strings" utility, so I keep the resource file on Windows.

Regards,
Greg

0 Kudos
mecej4
Honored Contributor III
917 Views

A Windows version of Strings may be obtained from various sources, e.g.:

     http://www.windows7library.com/blog/util/search-for-strings-within-executables/

 

0 Kudos
Reply