0

I want to create library (with my own code) which will use and include other libraries. The problem is that every time i want to use it's not enough to link my library but i also have to link all libraries that are used by my own.

So if my library uses - e.g - GLFW, GLEW and others, each project that wants to use code from my own library has to link to them too.

Is there a way where i can tell compiler/linker to add those 3rd party libraries to my own so i would need only to link one?

I'm working on Visual Studio 2013 (Community) and i'd prefer to build it as static library then dynamic, but as far as i see static library project can't even link other libraries. Do i have to build it as dnamic lib? Or is there some trick to get it done?

I hope i presented the problem well enough to understand it.

RippeR
  • 1,472
  • 1
  • 12
  • 23

1 Answers1

0

In your library source code, you can try and add the following:

#pragma comment (lib, "your_other_library")

Then this will implicitly link in the library without you having to explicitly specify it using the linker settings.

http://support.microsoft.com/kb/153901

PaulMcKenzie
  • 34,698
  • 4
  • 24
  • 45
  • The `#pragma` shouldn't bloat the code. For the second item, it looks like gcc doesn't have such a `#pragma`. – PaulMcKenzie Jan 31 '15 at 22:46
  • I meant that if someone uses different compiler than MSVC then they don't really need that when i reffered to it as 'bloat' ;). For the second question - i know that GCC doesnt have #pragma, what i asked is is there another solution to achieve "merging/linking to other static libraries" in library? I'm asking becouse i've never done it before and i would like to provide solution for those using GCC to build it like that too. – RippeR Jan 31 '15 at 22:52
  • Also i prefer project settings rather then non-portable piece of code, though it's only my point of view. – RippeR Jan 31 '15 at 22:53
  • Well for gcc you may not have a choice but document the libraries to link to. – PaulMcKenzie Jan 31 '15 at 22:54
  • Ok i was to fast to call it working. I'm trying for some time to use this approach and however i wont code it, it just doesnt work. It seems that it worked becouse i forgot to delete .lib files before compiling... Judging by file size etc. MSVC compiler just ignores it when building static library. – RippeR Feb 01 '15 at 00:04