Linking to static libraries that reference other static libraries in vs2013?

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Linking to static libraries that reference other static libraries in vs2013?

      My goal is to have my engine and its third-party dependencies compile together into 1 lib file, so my games would just need to include the engine's include files and link against the .lib.

      I've started work on it, and the engine compiles fine by itself into a .lib. However, when I create a test game that uses it, I get a bunch of linker errors. I'm using vs 2013.

      The engine has the allegro game programming library as its sole dependency, which i'm trying to link to statically as well.

      warning LNK4217: locally defined symbol _al_map_rgb imported in function "public: bool __thiscall AppLayer::initInstance(int,int)" (?initInstance@AppLayer@@QAE_NHH@Z) Engine\engine test\Engine.lib(app layer.obj) engine test

      These warnings come up for the allegro functions i use in the engine's application layer, followed by
      an error LNK2019: unresolved external symbol.

      The test app looks like this:

      #include "stdafx.h"
      #include "../engine.h"
      #pragma comment(lib, "Engine.lib")

      int main(int argc, char* argv[])
      {
      return Engine(argc, argv); // initializes the app layer, draw window to screen
      }

      i have engine properties -> librarian -> set link dependencies to yes, but still no luck. Any suggestions on getting static libraries referencing other static libraries to play nicely with each other?

      The post was edited 3 times, last by Neurone ().

    • What's the exact linker error? It should complain about a specific thing it's trying to link. Does that thing come from the library you're trying to build?

      I remember having issues with this in the past. Honestly, I just link all 3rd party libs in the executable project. This probably isn't the best way to do it but it's one of things that I've just always done. It works so I keep doing it. The only thing I absolutely can't stand about programming is getting all the dependencies sorted out.

      -Rez
    • Yeah this is driving me nuts. It seems that whenever i add a statically linked dependency to the engine's lib, i am required to tell the game utilizing the engine about it as well. That probably defeats the point of me creating a .lib for the engine itself for the game to link to.
    • Hi Neurone,

      It seems that whenever i add a statically linked dependency to the engine's lib, i am required to tell the game utilizing the engine about it as well.


      This is a fairly typical thing to get used to, most linkers (g++, clang) do not link libraries into other libraries, and instead require that you either;
      • Link the dependant libraries with your executable
      • Manually concatenate libraries using the ar tool
      This however means nothing to you because you are using Visual Studios lib tool. The lib tool offers the exact same functionality as ar in that you can combine multiple libraries into one, and as a bonus, Visual Studio even gives you a nice way of doing this. Under the project settings of your executable, there is a section on the left named 'Common Properties -> References' this allows you to set up extra properties for linking as well as some other settings. In this section you will see a list of all libraries you are linking to (that are also part of your solution), select your engine library, and set the 'Link Library Dependencies' to true. This will essentially link your executable with the dependencies of the project.

      [IMG:http://s13.postimg.org/b3fbp4jxj/Library_Dependencies.png]

      *Edit*
      I would also like to add for Linux users, that there is nothing stopping you from making a post-build step either in your make files, or project files (I use CodeLite and it offers this from within the IDE), where you do the ar concatenation.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz

      The post was edited 2 times, last by mholley519 ().

    • @mholley519: Thanks for the tip, it seems to work perfectly so far. Just one thing: how do I tell the game utilizing the engine where the engine lib's pdb file is? I'm getting the following:

      Engine.lib(engine.obj) : warning LNK4099: PDB 'vc120.pdb' was not found with 'Engine.lib(engine.obj)' or at 'D:\my documents\Visual Studio 2013\Projects\Engine\test\vc120.pdb'; linking object as if no debug info

      It seems that it expects it in the same directory as engine.lib, but i've set it to $(SolutionDir)temp/engine/debug
    • Generally what I do is place any linker artifacts (PDB, IDB, DLL, LIB) in the same folder, usually a special 'lib' folder, rather than the'temp' folder for the compiler artifacts, generally you don't care what the compiler spits out, but the linker stuff is useful. I would also recommend changing the name of your PDB to match your library, otherwise it will conflict with other libraries.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • This seems to have everything you need to know. msdn.microsoft.com/en-us/library/ms241613.aspx
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz