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

Building a static library from object files

Antonio_R_1
Beginner
1,471 Views

Hello,

We are using IntelVisual Fortran Composer XE 2011 (Update 7 Integration for Microsoft Visual Studio* 2010, 12.1.3518.2010) to create static libraries from object files previously generated. On some of our computers, when we build the static library project, no library is generated even though no error message is generated. We get the following information:

1>------ Rebuild All started: Project: Lib, Configuration: Release Win32 ------

1>Deleting intermediate files and output files for project 'Lib',configuration 'Release|Win32'.

1>
1>Build log written to"file://F:\Disk_CD\Disk_D\IF\Intel_Fortran\Lib\Lib\Release\BuildLog.htm"
1>Lib - 0 error(s), 0 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

The step "Creating library..." is missing. This appears to happen on some computers; however, if the static library is generated from Fortran files, the library is created properly. We can always create the library from Fortran files, but it would be great if someone could let us know the reasons for this issue.

Regards,

Antonio

0 Kudos
8 Replies
mecej4
Honored Contributor III
1,471 Views

The build-log file would contain the LIB command line and output. If LIB is called with nothing to do, it could just output a list of options and quit with "success" status. Please attach the buildlog.htm file or report the relevant lines in that file.

I don't know what you mean by "when generated from Fortran files". The librarian works with object files and module definition files. Whether the object files were produced by compiling Fortran sources or by compiling C/Assembler files is of little consequence.

0 Kudos
Antonio_R_1
Beginner
1,471 Views

I think I understand what you explained. If we generate the library from Fortran files or by just including directly (!) object files in the project should not matter. In practice and sometimes, it seems otherwise. You said "If LIB is called with nothing to do..."; I believe that that is the problem, why does Intel Fortran call LIB with nothing to do when we build the project using directly object files (when we build the project we want to get a library out of them)? Why does that only happen on some computers? On other computers, however, we can generate the static library directly from object files (no need to compile). Is it a configuration issue or can we do anything? 

I do not have access to the computer on which we have that problem right now; but I will post it as soon as I do. Thank you

0 Kudos
IanH
Honored Contributor II
1,471 Views

Antonio R. wrote:

I think I understand what you explained. If we generate the library from Fortran files or by just including directly (!) object files in the project should not matter. In practice and sometimes, it seems otherwise. You said "If LIB is called with nothing to do..."; I believe that that is the problem, why does Intel Fortran call LIB with nothing to do when we build the project using directly object files (when we build the project we want to get a library out of them)? Why does that only happen on some computers? On other computers, however, we can generate the static library directly from object files (no need to compile). Is it a configuration issue or can we do anything? 

I do not have access to the computer on which we have that problem right now; but I will post it as soon as I do. Thank you

I have to ask - why are you using a Fortran project to build a library from object files?

Where are the object files kept relative to the project file?  Be mindful that object files are regarded as temporary files by most project configurations, and subject to being deleted during a clean.

Does this only happen for release builds?  Are you using whole-of-program optimisation?  Are you varying which object files get included in the library based on the project configuration?

0 Kudos
Steven_L_Intel1
Employee
1,471 Views

There isn't a project type that allows you to just take a bunch of .obj files and make them into a library - at least by default. You could add a custom build step to issue the appropriate lib command. Normally you would need Fortran sources which then get compiled.

0 Kudos
Antonio_R_1
Beginner
1,471 Views

We use object files that we already have from a console project to build the static library (In this way we compile just once). This happens with debug and release modes, and we are using default project options, no especial optimization. We do not vary which object files are included depending on project configuration. Thank you guys for your comments

0 Kudos
IanH
Honored Contributor II
1,471 Views

The normal arrangement would be around the other way - compile the Fortran source (once) and archive it to a static library, then link that static library with a main program (compiled, once, from Fortran source) to make an executable.
 

0 Kudos
dboggs
New Contributor I
1,471 Views

Ian, I suspect that Antonio will not know what you mean by "archive it to a static library." In fact I don't know what you mean by that, yet I often do what Antonio wants (I think).

The procedure that works for me is to use the Microsoft command line "lib tool" to put obj files into a lib file. This tool is provided in the IVF package. The only hard part is FINDING the thing--it is well buried, and undocumented (as far as I can tell). I get there by the sequence START > All Programs > Intel Parallel Studio > Command Prompt > Parallel Studio EX with ... > IA32 Visual Studio 2010 Mode. It will probably be different for different installations.

Once you have the lib tool in a command window, you simply type a variety of useful commands. For example,

     LIB /LIST libname.lib

will produce a list of all the obj routines in the library libname. Better yet,

     LIB libname.lib newfile.obj

will insert an existing object file newfile into the existing library libname--which I think is exactly what Antonio wants to do.

Is this what Ian means by "archive it to a static library."?

To find more syntax details and other useful commands you have to Google it and hope for the best. At least that's what I had to do--Intel doesn't bother to put any of this into the Fortran documentation.

0 Kudos
IanH
Honored Contributor II
1,471 Views

dboggs wrote:
Better yet,

     LIB libname.lib newfile.obj

will insert an existing object file newfile into the existing library libname--which I think is exactly what Antonio wants to do.

Is this what Ian means by "archive it to a static library."?

Yes.  In terms of nouns, library and archive are synonyms in this context (archive is the term used on other platforms), in terms of verbs the sense is "to store".

LIB.exe is a Microsoft tool (it is just a thin wrapper around LINK.exe).  See http://msdn.microsoft.com/en-us/library/7ykb2k5f.aspx for documentation.

A Fortran project that produces a static library calls LIB.exe for you as part of a build.  Expanding on my previous point - typically you have a project that compiles Fortran source to object code and stores that object code in a library file, you then have another project that uses that library file along with other Fortran source to create an executable or DLL. Making the executable from the source, then creating the library as an after-thought from the intermediate object code (and still using a Fortran static library project) is very atypical - and perhaps that's relevant to the issue that the OP sees.

0 Kudos
Reply