- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm working with Intel Fortran 10. I'll try to explain as easy as possible my problem. I've got three static library A,B and C. B and C uses some functions embedded in A. When I create an application which uses B and C I have to link A also.I don't want this, I want to embed the code of A directly inside B and C to make my application linking only B and C. I do this by setting "Link Library Dependencies" to YES when building B and C but when my application links B and C it finds multiple definitions of A.
Is possible to embed the code of A inside B and C without making the function of A being visible also from B and C ?
Hope to be clear...
Thanks,
roberto
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think you may need to upgrade to version 11 to get this to work right. You've got the right idea - the "library dependences" option should merge library A with B or C when you build those. I am not sure why you'd get multiple definitions, though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think you may need to upgrade to version 11 to get this to work right. You've got the right idea - the "library dependences" option should merge library A with B or C when you build those. I am not sure why you'd get multiple definitions, though.
Well, suppose the function fprintf() being in A and both B and C calls fprintf(). If I link B and C merged with A then the code of fprintf() is copied inside B and C but fprintf() becomes also "visible" outside B and C. So when I link B and C in the same project, the linker finds 2 definitions of fprintf(), one in library B and the other in library C. If I need to link also the library A the linker will find a third definition of fprintf().
In my library, I just want to merge the external functions without making this functions visible from my library too. Some kind of "private merging" of external functions.
No way with version 10 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I link B and C merged with A then the code of fprintf() is copied inside B and C but fprintf() becomes also "visible" outside B and C.
Don't do it, then.
Seriously, a "normal" way to use static libraries is to maintain A separately from B and C, not to embed A within B and C. Yes, it's a bit inconvenient having to keep all dependent libraries around, but it's still more inconvenient to have multiple copies of the same code hanging around (especially if they come in different versions)...
In other words, do not include A into projects of B and C -- only in the target exe.
If you still want to do it the old way, you can try using /force:multiple linker flag. (I'm not sure it will always work, but you can give it a try).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I am right, when a function or subroutine is linked from a static library all the functions and subroutine that where included in the same .obj file are linked at the same time.
Example
Library A
A123.for -> A123.obj source containing A1 A2 and A3 functions
Library B
Using A1 and A2 functions
Library C
Using A1 and A3 functions
In this case, if you create an .exe including B+A lib and C+A lib, you will have a multiple definition error for A1 function because A123.obj is included in each library.
So if you want to avoid multiple definition when including the static library A in static libraries B and C, you must build A with each source file includind only one function or subroutine or carrefully check the cross references of your functions and subroutines in each source file of A library.
I think that Yougoslav advice to not include A library in B and C libraies is the simpliest way.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page