3

I am making a library using C++ 11, and my library uses several other libraries, like FreeImage and GLFW. I would like to be able to distribute my library in a way that the end users will not be required to install the other libraries; this will prevent versioning issues and keep life easy.

I am developing using Visual Studio 2013 Pro under windows, although the library code is cross-platform (so I eventually should be able to build versions for OS X and Linux). I am only worrying about getting this working under Windows at the moment.

Currently, I am making a static library and have added the dependant libs to the project in the solution explorer. I can use this library in other projects, but I have to link to the dependant libraries.

I think what I want is called a "convenience library" under Linux, but I am not sure.

This project is intended as an educational resource for my students, and I intend to make it open source and provide both the full project and prebuilt binaries. It would be great if the pre-built binaries didn't require installation of every library I am using; they are all open source projects themselves and freely available, but I can't help but think that rolling everything into one library would be very convenient for the end users.

I've tried looking around on the internet for information on this, but I am drowned in search results for Linux-only solutions (and even then, not necessarily related to my exact problem).

Thank you in advance, ladies and gentlemen.

Darren
  • 253
  • 1
  • 9
  • 2
    On Linux you can link a shared library into another shared library... BTW, since it is for teaching I would on the contrary expect (and help) students to compile from source code and not distribute any binaries. – Basile Starynkevitch Oct 19 '14 at 16:24
  • @BasileStarynkevitch: It depends. If this is a course on computer graphics, then the C++ compiler and linker are just tools, and you don't want to waste too much of students' time to learn the particularities of a particular toolset. If the course is about software engineering and programming in general, then I would agree that dealing with libraries should be a central topic. – Christian Hackl Oct 19 '14 at 16:40
  • 1
    FreeImage is GPL and you have to distrbte the source with it. If you make a regrouping library, you'll have to distribute the source code of the whole library along with it. The fact you're teaching doesn't put you above the license terms... – Christophe Oct 19 '14 at 16:47
  • possible duplicate of [How to merge two windows vc static library into one](http://stackoverflow.com/questions/13492365/how-to-merge-two-windows-vc-static-library-into-one) – Christophe Oct 19 '14 at 16:51
  • @Christophe I will be providing both full source AND a precompiled binary; it's just that if the end-user prefers to just grab the pre-compiled binary and use it, I don't wish to foist on them the requirement to install FreeImage. – Darren Oct 19 '14 at 17:31
  • @Basile Starynkevitch I will be having them at some point go over the library code and build it themselves, but the appropriate time to do that is not at the start. First year students at the start of their second term don't need to deal with dependency hassles if it's avoidable, is my thinking :) – Darren Oct 19 '14 at 17:36
  • I agree, but even in a course on computer graphics, students are supposed (as a side effect) to be familiar with compiling their own software. Asking them to build a well-documented library would help them in learning that. – Basile Starynkevitch Oct 19 '14 at 17:46

1 Answers1

1

Try this:

lib.exe /out:convenience.lib myownlib.lib freeimage.lib glfw.lib

(The filenames are just examples, of course.)

Christian Hackl
  • 27,051
  • 3
  • 32
  • 62
  • Looks intersting, but I get error C1905 "Front and back end not compatible" even if I only try to move ONE lib into itself i.e. lib.exe /out:convenience.lib myownlib.lib – Darren Oct 19 '14 at 18:25
  • @Darren: "move into itself" sounds wrong. You are creating a new file, i.e. "convenience.lib" does not exist before. – Christian Hackl Oct 20 '14 at 07:53
  • Yes, ideally I am doing that, but I tried to track down what was causing the incompatibility and even just "moving" one library into the convenience library gives the error, like so: "lib.exe /out:convenience.lib myownlib.lib". This confuses me, as how can a single library have incompatible front and back end? – Darren Oct 21 '14 at 21:29
  • @Darren: Did you build "myownlib.lib" with the same toolset that lib.exe belongs to? – Christian Hackl Oct 22 '14 at 18:44
  • Yes, same installation of VS2013. Oh well, I have gotten around it all without using lib.exe, after some messing around with the project preferences. I believe all I needed to do was add the libraries as "Additional Dependencies" and set "Link Library Dependencies" to "Yes" in the Librarian/General settings. – Darren Oct 25 '14 at 03:15