2
votes

I am trying to create a static library of my own. I am however using a third party static lib as well. Now, in my static library I have a .h file which has the client's API in it. All the implementation details are in the .cpp file. No issues there. But, some of my functions in the .cpp file rely on this third party lib.

I cannot ask them to install the third party static lib and need to somehow include it in my static lib. Some of the steps I took are as follows:

  1. I included it in my static lib project.
  2. I added a reference to the librarian so it can pick it up in vs 2008.

So far so good. No issues.

However, when I try to create the library I seem to be getting LNK4221 as well as LNK4006 warnings. These are all related to the third party obj files. In the case of LNK4006, I see multiple function declarations for different classes and it says that the second definition is ignored. In the case of LNK4221, it seems to elude that none of my functions that I am calling are using that obj and thus it will never be used.

So, the question is how do I get rid of these warnings? I know I am using the third party static lib and my original testapp works with it. The question here is to provide a static library.

Further research has shown that there are people that have used multiple static libraries within an existing static lib. But, at the moment, I am not sure how else to proceed. it seems like I am generating all those warnings for every obj in the lib.
perhaps I need to isolate the obj I am using that just use that.

But these are just some thoughts. If there is anyone who might be of assistance with this I would appreciate it. I did find some posts here of something very similar but there did not seem to be a solution that is viable for me.

hope this is clear and precise.

After seeing whats out there via google and msdn

Updating: Here were some of the linker related warning message when I just simply added the third party lib to vs2008

Compiling... 1>TFLib.cpp 1>Creating library... 1>cryptlib.lib(pch.obj) : warning LNK4221: no public symbols found; archive member will be inaccessible 1>cryptlib.lib(3way.obj) : warning LNK4006: "void __cdecl CryptoPP::ThreeWay_TestInstantiations(void)" (?ThreeWay_TestInstantiations@CryptoPP@@YAXXZ) already defined in cryptlib.lib(3way.obj); second definition ignored 1>cryptlib.lib(3way.obj) : warning LNK4006: "public: virtual void __thiscall CryptoPP::ThreeWay::Base::UncheckedSetKey(unsigned char const *,unsigned int,class CryptoPP::NameValuePairs const &)" (?UncheckedSetKey@Base@ThreeWay@CryptoPP@@UAEXPBEIABVNameValuePairs@3@@Z) already defined in cryptlib.lib(3way.obj); second definition ignored 1>cryptlib.lib(3way.obj) : warning LNK4006: "public: virtual void __thiscall CryptoPP::ThreeWay::Enc::ProcessAndXorBlock(unsigned char const *,unsigned char const *,unsigned char *)const " (?ProcessAndXorBlock@Enc@ThreeWay@CryptoPP@@UBEXPBE0PAE@Z) already defined in cryptlib.lib(3way.obj); second definition ignored 1>cryptlib.lib(3way.obj) : warning LNK4006: "public: virtual void __thiscall CryptoPP::ThreeWay::Dec::ProcessAndXorBlock(unsigned char const *,unsigned char const *,unsigned char *)const " (?ProcessAndXorBlock@Dec@ThreeWay@CryptoPP@@UBEXPBE0PAE@Z) already defined in cryptlib.lib(3way.obj); second definition ignored 1>cryptlib.lib(3way.obj) : warning LNK4221: no public symbols found; archive member will be inaccessible 1>cryptlib.lib(adler32.obj) : warning LNK4006: "public: virtual void __thiscall CryptoPP::Adler32::Update(unsigned char const *,unsigned int)" (?Update@Adler32@CryptoPP@@UAEXPBEI@Z) already defined in cryptlib.lib(adler32.obj); second definition ignored 1>cryptlib.lib(adler32.obj) : warning LNK4006: "public: virtual void __thiscall CryptoPP::Adler32::TruncatedFinal(unsigned char *,unsigned int)" (?TruncatedFinal@Adler32@CryptoPP@@UAEXPAEI@Z) already defined in cryptlib.lib(adler32.obj); second definition ignored 1>cryptlib.lib(adler32.obj) : warning LNK4221: no public symbols found; archive member will be inaccessible 1>cryptlib.lib(algparam.obj) : warning LNK4006: "public: virtual bool __thiscall CryptoPP::CombinedNameValuePairs::GetVoidValue(char const *,class type_info const &,void *)const " (?GetVoidValue@CombinedNameValuePairs@CryptoPP@@UBE_NPBDABVtype_info@@PAX@Z) already defined in cryptlib.lib(algparam.obj); second definition ignored 1>cryptlib.lib(algparam.obj) : warning LNK4006: "protected: void __thiscall CryptoPP::AlgorithmParametersBase::operator=(class CryptoPP::AlgorithmParametersBase const &)" (??4AlgorithmParametersBase@CryptoPP@@IAEXABV01@@Z) already defined in cryptlib.lib(algparam.obj); second definition ignored 1>cryptlib.lib(algparam.obj) : warning LNK4006: "public: bool __thiscall CryptoPP::AlgorithmParametersBase::GetVoidValue(char const *,class type_info const &,void *)const " (?GetVoidValue@AlgorithmParametersBase@CryptoPP@@QBE_NPBDABVtype_info@@PAX@Z) already defined in cryptlib.lib(algparam.obj); second definition ignored 1>cryptlib.lib(algparam.obj) : warning LNK4006: "public: __thiscall CryptoPP::AlgorithmParameters::AlgorithmParameters(void)" (??0AlgorithmParameters@CryptoPP@@QAE@XZ) already defined in cryptlib.lib(algparam.obj); second definition ignored 1>cryptlib.lib(algparam.obj) : warning LNK4006: "public: __thiscall CryptoPP::AlgorithmParameters::AlgorithmParameters(class CryptoPP::AlgorithmParameters const &)" (??0AlgorithmParameters@CryptoPP@@QAE@ABV01@@Z) already defined in cryptlib.lib(algparam.obj); second definition ignored 1>cryptlib.lib(algparam.obj) : warning LNK4006: "public: class CryptoPP::AlgorithmParameters & __thiscall CryptoPP::AlgorithmParameters::operator=(class CryptoPP::AlgorithmParameters const &)" (??4AlgorithmParameters@CryptoPP@@QAEAAV01@ABV01@@Z) already defined in cryptlib.lib(algparam.obj); second definition ignored 1>cryptlib.lib(algparam.obj) : warning LNK4006: "public: virtual bool __thiscall CryptoPP::AlgorithmParameters::GetVoidValue(char const *,class type_info const &,void )const " (?GetVoidValue@AlgorithmParameters@CryptoPP@@UBE_NPBDABVtype_info@@PAX@Z) already defined in cryptlib.lib(algparam.obj); second definition ignored 1>cryptlib.lib(algparam.obj) : warning LNK4006: "bool (__cdecl CryptoPP::g_pAssignIntToInteger)(class type_info const &,void *,void const *)" (?g_pAssignIntToInteger@CryptoPP@@3P6A_NABVtype_info@@PAXPBX@ZA) already defined in cryptlib.lib(algparam.obj); second definition ignored 1>cryptlib.lib(algparam.obj) : warning LNK4221: no public symbols found; archive member will be inaccessible

and at the end...

1>Build log was saved at "file://d:\Documents and Settings\Khurram\My Documents\Visual Studio 2008\Projects\TFLib\TFLib\Debug\BuildLog.htm" 1>TFLib - 0 error(s), 1354 warning(s) ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

The log is too big to share but this should do it. Unless there is a way to use attachments here which I am not sure how. But this should be sufficient to show the issue.

1
Any specific reason you cannot distribute your library as a dll and link the static 3rd-party library into it?Timo Geusch
As a requirement I can't distribute it as a dll. It has to be a static lib. I have no control over that part.user300938
Re your update - if you are building a static library, no linking will take place. Ergo, your project is not building a static library. And also, not everything is best done using the IDE - consider using a command line prompt.anon

1 Answers

2
votes

Static libraries are only linked when you build an executable or a DLL. They are not linked when you create the static libraries themselves. If you want to concatenate two static libraries, the lib.exe tool should be able to do this for you. However, I don't see why you can't live with having two (or more) static libraries in your final projets.