I have a set of statically-compiled libraries, with fairly deep-running dependencies between the libraries. For example, the executable X uses libraries A and B, A uses library C, and B uses libraries C and D:
When I link X with A and B, I don't want to get errors if C and D were not also added to the list of libraries—the fact that A and B use these libraries internally is an implementation detail that X should not need to know about. Also, when new dependencies are added anywhere in the dependency tree, the project file of any program that uses A or B would have to be reconfigured. For a deep dependency tree, the list of required libraries can become really long and hard to maintain.
So, I am using the 'Additional Dependencies' setting of the Librarian section in the A project, adding C.lib. And in the same section of B's project, I add C.lib and D.lib. The effect of this is that the librarian bundles C.lib into A.lib, and C.lib and D.lib into B.lib.
Warning 1909 Can't Create .lnk Due To Read Only Setting Problem In Word
When I link X, however, both A.lib and B.lib contain their own copy of C.lib. This leads to tons of warnings along the lines of
A.lib(c.obj) : warning LNK4006 'symbol' (_symbol) already defined in B.lib(c.obj); second definition ignored.
How can I accomplish this without getting warnings? Is there a way to simply disable the warning, or is there a better way?
EDIT: I have seen more than one answer suggesting that, for the lack of a better alternative, I simply disable the warning. Well, this is part of the problem: I don't even know how to disable it!
abatishchev
71.4k7070 gold badges269269 silver badges399399 bronze badges
flodinflodin
4,17822 gold badges2121 silver badges3535 bronze badges
9 Answers
As far as I know you can't disable linker warnings. However, you can ignore some of them, using command line parameter of linker eg. /ignore:4006
Put it in your project properties under linker->command line setting (don't remember exact location).
Also read this:
Wacek
3,92122 gold badges1515 silver badges2727 bronze badges
Update If you can build all involved project in single solution, try this:
It should work. It doesn't invalidate anything I said before, the basic model of building C/C++ programs stays the same. VS (at least 2005 and newer) is simply smart enough to add all needed static libraries to linker command line. You can see it in project properties.
Of course this method won't help if you need to use already compiled static libraries. Then you need to add them all to exe or dll project that directly or indirectly uses them.
I don't think you can do anything about that. You should remove references to other static libs from static libs projects and add all needed static libs projects as dependences of exe or dll projects. You will just have to live with fact that any project that includes A.lib or B.lib also needs to include C.lib.
As an alternative you can turn your libraries into dlls which provide a richer model.
Statically compiled libraries simply aren't real libraries with dependency information, etc, like dlls. See how, when you build them, you don't really need to provide libraries they depend on? Headers are all that's needed. See? You can't even really say static libraries depend on something.
Static library is just an archive of compiled and not yet linked object code. It's not consistent whole. Each object file is compiled separately and remains separate entity inside the library. Linking happens when you build exe or dll. That's when you need to provide all object code. That's when all the symbol and dependency resolving happens.
If you add other static libraries to static library dependencies, librarian will simply copy all code together. Then, when building exe, linker will give you lots of warnings about duplicate symbols. You might be able to block those warnings (I don't know how) but be careful. It may conceal real problems like real duplicate symbols with differing definitions. And if you have static data defined in libraries, it probably won't work anyway.
Tomek SzpakowiczTomek Szpakowicz
9,90411 gold badge2828 silver badges5050 bronze badges
You could create one library which contains A, B, C & D and then link X against that.
Since it's a library, only object modules which are actually referenced will get linked into the final executable.
FerruccioFerruccio
81.9k3535 gold badges201201 silver badges286286 bronze badges
Microsoft (R) Incremental Linker Version 9.00.x (link.exe) knows argument /ignore:4006
abatishchevabatishchev
71.4k7070 gold badges269269 silver badges399399 bronze badges
Note that one way of getting this warning is to define a member function in a header without the inline statement:
MarkMark
The problem is you are not localizing library C's symbols. What is a curb park on the road youtube. So you have a ODR violation when you link in A and B. You need to have a way to make these private. By default all symbols are exported. One way to do this is to have a special linker definition file for both A and B that explicitly mention which files need to be exported.
[1] ODR = One Definition Rule.
dirkgentlydirkgently
92.4k1616 gold badges114114 silver badges177177 bronze badges
I think the best course of action here will be to ignore/disable the linker warnings(LNK4006) since C.lib needs to be part of both A.Lib and B.lib and A.Lib does not need to know that B.lib itself uses C.Lib.
AutodidactAutodidact
17.4k1414 gold badges5757 silver badges7777 bronze badges
This may not fix your link error, but it might help with your dependency tree issue.
What I do, is just use a #pragma to include a lib in the .cpp file that needs it. For example:
Like I said, I'm not sure it would keep the symbols in that object file, I'd have to whip up an example to try it out.
LarryFLarryF
3,62633 gold badges2424 silver badges3939 bronze badges
Poor flodin seems frustrated that nobody will explain how to disable the linker warnings. Well, I've had a similar problem, and for years I have simply lived with the fact that several hundred warnings were displayed. Now, however, thanks to the info from Link /ignore, I figured out how to disable the linker warnings.
I'm using Visual Studio 2008. In Project -> Settings -> Configuration Properties -> Librarian -> Command Line -> Additional Options, I added '/ignore:4006' (without the quotes). Now my warnings are gone!
birchbirch
Not the answer you're looking for? Browse other questions tagged visual-c++modulewarnings or ask your own question.
Posted by4 years ago
Archived
Hello all, fairly new to linux and trying to install Elementary OS to the SD Card. However, I can't create a new symbolic link to the chroots directory on any USB drives.
I've tried on USB and also SD Card and always get the same error: ln: failed to create symbolic link 'chroots': Read-only file system.
Here is the command I'm running in crosh: 'sudo ln -s /media/removable/chrome-disk/chroots chroots'
I'm on a Toshiba Chromebook 2.
Edit: I formatted ext4 or ext2 via gparted. I can create directories on them without issue.
3 comments
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |