8

I'm trying to use static library that include other static libraries.

There are two projects: Engine, MyGame

'Engine' is going to produce Engine.lib

'MyGame' is going to use Engine.lib when it is linking.

Following is the build message that I'm getting from visual studio 2012:

1>------ Rebuild All started: Project: Engine, Configuration: Debug Win32 ------
2>------ Rebuild All started: Project: MyGame, Configuration: Debug Win32 ------
1>  Precompiled.cpp
2>  Main.cpp
2>LINK : fatal error LNK1104: cannot open file 'D:\klee\Engine\Debug\Engine.lib'
1>  RenderGame.cpp
1>  RenderDebug.cpp
1>  MsgHandler.cpp
1>  Main.cpp
1>  Log.cpp
1>  Input.cpp
1>  Interface.cpp
1>  Helper.cpp
1>  GameObject.cpp
1>  Framework.cpp
1>  Engine.cpp
1>  Config.cpp
1>  Component.cpp
1>  Generating Code...
1>  Guicon.cpp
1>glu32.lib(GLU32.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in glew32.lib(glew32.dll); second definition ignored
1>glu32.lib(GLU32.dll) : 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
1>opengl32.lib(OPENGL32.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in glew32.lib(glew32.dll); second definition ignored
1>opengl32.lib(OPENGL32.dll) : 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
1>SDL2.lib(SDL2.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in glew32.lib(glew32.dll); second definition ignored
1>SDL2.lib(SDL2.dll) : 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
1>  Engine.vcxproj -> D:\klee\Engine\Debug\Engine.lib
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========

At first, it seems like 'MyGame' fails to find Engine.lib, but the project does produce executable that runs fine.

Second, 'Engine' includes other libraries(SDL2, OpenGL, GLEW) to produce its new library, but it says symbols are duplicated.

  1. What does 'symbol' exactly mean?

  2. What does it mean symbol being 'public' when linking?

  3. If these warnings are critical, why is it and how do I fix it?

  4. How do I configure build sequence between projects?

  5. Any best practices using external libraries in my project?

  6. Two projects shares some dll(SDL2.dll, glew.dll). If other users are going to use this Engine.lib, how do I provide these dlls?

Thank you.

1 Answer 1

6

Some answers, in logical (not sequential) order:

  • re: 4: MyGame must include a reference to Engine. This, among others, will force MyGame to start building only after Engine had finished and avoid the error you're getting. Note that one older apparatus for forcing build order is still respected ('project dependencies'), but you'd need an exceptional reason to use it today.

  • re 1: A symbol in this context is an 'atom' of linker work. It is either a function or a global variable, that can be consumed in multiple translation units.

  • re 3: These warnings are not critical. LNK4006 here ultimately comes from static libs including reference to other static libs (which is allowed but not encouraged by MS). The LNK4221 is most probably misuse of wizard-generated precompiled header files

  • re 6: In principle your installer must install any 3rd party components you consume, and wire them up so your binaries find them (registry keys, environment variables, whatever). That is probably the case for SDL2 (is that it?), but OpenGL is in fact shipped with windows - so unless you're using some exotic version you should be ok.

2
  • 2
    Didn't expect to get an answer to this one for it has been a year... but Thanks! May 30, 2015 at 8:40
  • Whaddayaknow, SO's markdown modifies manually numbered lists to be sequential. Didn't notice when typing. May 30, 2015 at 17:42

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.