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

Link static lib: How to add unreferenced routines to exe



The documentation about static library say

"If you use a static library, only those routines actually needed by the program are incorporated into the executable image (.EXE)."


Is there any option to skip this behavior and include all the routines in the executable image. Consider the scenario with Visual Studio 2015 and Intel Fortran Composer 2016

  1. Fortran static lib expose routines to C/C++ using !DEC$ ATTRIBUTES DLLEXPORT
  2. C++ executable link the static lib. The exe shall have all the exposed routines including the unreferenced routines.


Labels (1)
0 Kudos
3 Replies
Black Belt

Why would you want to do it, and generate EXEs and DLLs of enormous size, which would consist for the most part of useless code, and whose generation would take the linker much time, and the loading of which would be much slower? What gains do you expect?

Currently, the way linkers usually work is that the smallest indivisible unit of inclusion is an OBJ file, not an individual routine, and if one of the external symbols in an OBJ is required, all the routines in the OBJ will be included. You are asking for a way of making the entire LIB file the smallest indivisible unit.


Thanks Mecej4 for the quick reply. Your concerns for the size is genuine and thanks for considering that.


My scenario is a bit complex and involves multiple C++ & Fortran dlls, static libs and executables. I will try to add simplified scenario later some time, and attach some code as well.


If there is any settings that can disable the default behavior, that would be great.

Currently, I have created wrappers for all exposed routines in a single file with a dummy routine and call the dummy routine from C++ executable, in order to load all exposed routines.

0 Kudos
Black Belt Retired Employee

There is no setting to have the linker include unreferenced objects from a library. As @mecej4 says, you could use a single .obj file, or even extract all the objects from a library to a single .obj. What I am not seeing, though, is why you want to do this - how do you intend to "see" the unreferenced routines?