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

Using two static libraries; LNK2019

stutzbach
Beginner
1,069 Views
Hello,

I want to use two static libraries. An Executable uses a static library #1and this one uses static library #2.

A very silly question, but I dont know the syntax how to add library #2 in the properties of library #1???
(Under Additional Library Directories....)

Otherwise, I always get an error LNK2019....

Greetings,

Moritz
0 Kudos
4 Replies
mecej4
Honored Contributor III
1,069 Views
Your notion of dependencies is based on the linker's point of view. However, note that building a static library requires only the objects that go into that library, and whether or not that those objects contain unsatisfied references is irrelevant from the librarian's point of view.

Until you reach the point of building an EXE or DLL that uses routines in the libraries, even subroutines and functions in a single library that call other routines in the same library will contain unresolved external symbols, even if a cross-reference table is built and maintained in the library to improve the linker's performance at link time.

Therefore, in the project for your EXE, list lib#1 and lib#2 as dependencies. Neither library project should be listed as depending on the other library project.
0 Kudos
Steven_L_Intel1
Employee
1,069 Views
If you make a library project the dependent of an executable project, the library will be linked in automatically. If you make a library a dependent of another library, there is an option (in VS08 and VS10) on the Librarian property page to merge the dependent library into the parent. I don't think that's really what you want, though.
0 Kudos
stutzbach
Beginner
1,069 Views
Hmm, okay...I did not really understand what to do now :).Perhaps it's better if I explain my problem to you.

For my masther thesis I have to write a program using different thermodynamic models. They all have the same properties with little differences. The whole program shall be implemented object-oriented.

Now I decided to create for every thermodynamic model a static library (6 at all). Depending on what the user especially wants to do an object of the particular thermodynamic model shall be created. I want to do this with a factory pattern. It works, when the factory pattern and a thermodynamic model (or more) are all in the same library. But I want it this way:

Executable (user) -> factory pattern (static library) -> thermodynamic model (6 options)

And using this solution I allways get the LNK2019-error (Of course the objects are created in the executable). Acutally, do you think this is possible? Or could I usea dynamic link library (at this time I do not really understand the whole difference between static and dynamic libraries). Would be nice if somebody takes himself the time and could a think a minute about this problem. Honestly, slowly I get angry cause of this LNK2019...

Moritz
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,069 Views
The classic, "old school" solution is to simply put both static libraries (factory+selected thermodynamic model) into the .exe's linker properties (Using linker/input/additional dependencies).

Alternatively, for the .exe, from main menu use Project/Project dependencies, and specify that you want it to be dependent on both static libraries.

There is also the third way, closest to what you want. where you "glue" both static libraries into one. In Project dependencies, specify that .exe depends on factory.lib, and factory on model.lib. For factory.lib, specify Librarian/Link Library Dependencies to "Yes".

However, I'll bite: if the models have "all have the same properties with little differences", and thus can be made to have identical interfaces, why don't you make 6 dlls out of them? Sounds like a perfect candidate for that. In that way, the linking will go at run-time, and user could potentially select different models by just changing the dll, not recompiling everything.
0 Kudos
Reply