0

I'm writing a library for in-house use and I want to automate the linking of static library (.lib) files so users don't have to know all the libraries they need. We use Visual Studio 2015 so I've knocked something up using pragma which seems to work but I'm getting a lot or warnings, which I presume are caused by what I'm doing.

Warning LNK4221 This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library

I include this code in all the public facing interface header files and extend it to include internal and external libraries necessary.

#ifndef GFXK_LIBS_NET_IMPORT__
#define GFXK_LIBS_NET_IMPORT__

#ifdef _DEBUG

#ifdef WIN32
#pragma comment( lib, "gfxk_net_Debug_Win32-v140.lib" )
#else
#pragma comment( lib, "gfxk_net_Debug_x64-v140.lib" )
#endif

#else

#ifdef WIN32
#pragma comment( lib, "gfxk_net_Release_Win32-v140" )
#else
#pragma comment( lib, "gfxk_net_Release_x64-v140" )
#endif

#endif /*_DEBUG*/

#endif /*GFXK_LIBS_NET_IMPORT__*/

My question is how do I do this nicely so that I can remove this hack job. I'm looking for something similar to what Boost does with it's auto linking, I can't find out how to do this. I'm not too worried about cross platform as library targets only Windows at this time.

Treebeard
  • 322
  • 1
  • 9
  • This doesn't address the question, but names that contain two consecutive underscores (`__GFXK_LIBS_NET_IMPORT__`) and names that begin with an underscore followed by a capital letter are reserved for use by the implementation. Don't use them in your code. – Pete Becker Jul 10 '18 at 15:11
  • Whoops, I didn't mean to do that – Treebeard Jul 10 '18 at 15:48

1 Answers1

1

You can specify .libs path in your project settings Configuration Properties -> Linker -> Input -> Additional dependencies. You may specify different settings for different configurations and platforms. That would be a clearer way.

But the warning won't appear after you add functions to your .lib and use them in your project. Warning is just saying that this pragma-lib statement is pointless as no functions are really imported.

V. Kravchenko
  • 1,859
  • 10
  • 12
  • Thanks for the answer. I do that at the moment for hidden linkage (e.g. my 'compression' library includes 'zlib.lib'). What I'm trying to do it more including a libraries own lib file from it's own header so that the users don't have to do this for all the libraries they're using. Just to speed up users dev time. – Treebeard Jul 10 '18 at 15:41