3

While using C++ in Visual Studio 2013, I've come across a really weird warning/bug thing.

I have a static library and a console application.

Static library imports 4 3rd party .lib files, and their headers. Console application imports the static library and the headers of the original 4 .lib files, so that I can use the code from the original 4 .libs and my .lib.

(I think this is the right setup in this situation, if there is a better way, do tell!)

However, when I build the static library, I get a 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" for each .lib imported.

But where is it getting the code if not from the libraries? If I remove the .libs from being imported, the build fails stating that it needs them! I don't know what to do in a situation like this. I would be happy enough to just leave the .libs being imported as is and ignore the warnings, but when I try to disable them (Under disable specific warning, "4221", in the compiler options), the warnings are not disabled!

Edit: The 4 3rd party .libs are standalone - they do not use each other's code so I do need to import all of them.

I am truly at a loss - any advice would be much appreciated.

hnefatl
  • 5,860
  • 2
  • 27
  • 49
  • No, none of the projects in question use precompiled headers, so I didn't see how it could help :/ – hnefatl Aug 07 '14 at 11:12
  • 2
    You may have empty .cpp file which only includes header for lib, that will generate warning. Check the warning to find out .obj file and then check corresponding .cpp file – Ivan Lebediev Aug 07 '14 at 11:33
  • "The build fails stating that it needs them" is a very odd linker error message. Quoting error messages accurately is very important. Linker warnings like that are nothing to worry about, you cannot suppress them. Use the /verbose linker option to see how .lib files get used. – Hans Passant Aug 07 '14 at 11:35
  • possible duplicate of [Linking static libraries to other static libraries](http://stackoverflow.com/questions/2157629/linking-static-libraries-to-other-static-libraries) – Werner Henze Aug 07 '14 at 11:44

1 Answers1

1

I found a way of disabling the warnings using /ignore: on the linker command line, but I'm still confused as to why the linker gave the warnings in the first place, when removing the library as input caused multiple "unresolved external symbol" errors.

Oh well, problem (sorta) solved.

hnefatl
  • 5,860
  • 2
  • 27
  • 49