I'm creating a personal C++ framework of sorts, just an interface to common stuff I use between projects. It's a static library. It makes use of a fair bit of STL and Boost. In order to use it I have to statically link to a couple Boost static libraries (.lib's).
Isn't there any way I can have my framework include the Boost dependencies (ie. compile the Boost libraries into my library)? So it doesn't require additional linking for other projects.
Thanks in advance
static linking = compile the libraries into your program/library. So either you're already doing what you want to be doing, or you're not telling us something.
Yeah... That's what I thought.
I've got it as a static link project in Code::Blocks under Build Options -> Linker Settings -> Link -> "..\boost\libboost_regex-mgw34-mt-d-1_37.lib" etc.
It compiles Framework.lib, which I link to in a new project, but it throws the standard "undefined reference" to boost::basic_regex if I don't link to those libs in the new project as well.
Without looking at your code, static linking should link in the functions that are used in your framework code. But your framework library doesn't have a function called boost::basic_regex in it (you included the binary for it with the linking, but that doesn't get added to the table of contents of the library). If you call that function from your main program, then you'll need the boost library as well. OTOH, if you only call your framework functions then you shouldn't get any errors.
(I.e., just because you write a program that uses printf doesn't mean you can link some other program that needs printf to it instead of to the C runtime library.)
Okay, then the question would be: is it possible to get the framework dependencies (boost static libraries) added to the table of contents of the framework library. Compile multiple library files into one.
I am not as wise in the ways of linkers as I should be, but I do not believe that the functions are necessarily included in a way that they can even be called separately. (They probably are, but I wouldn't be able to guarantee it.)
If for whatever reason you want to only link your library in, then all the functionality needs to be in your library. If you don't want to use boost's library, but you want to call this regex function, then you're not done writing your library yet until you have a function that does what you want. (It may not do much more than call boost's function, but if you don't want the library to be linked in you can't leave it to boost to do.)
Well, that's gonna be a hassle. Thanks tabstop.
You can, if you want to, create a new library from several libraries. There are some interesting challenges in doing so, and I would suggest that you don't, but it is technically possible. The process goes something like this:
- Extract library 1 and library 2 into current directory.
- Buld a new library from the extracted files.
Remember, a static library is simply a collection of object files (a bit like a zip archive, but with no compression), so the content of it is just like the object files you get when you compile your application code.
One of the problems with splitting and merging libraries is that you need to be careful about dependancies and the order that the library content is introduced into the final application. If library A uses library B functions, then it the order must be libA then libB, as the linker will only search each library once. This means that if libB is linked before libA, the functions in libA that uses libB will be "not found".
With Visual Studio's LIB.exe it's easy - just add the libs you want to include on the command line when LIB is called.
Yes, you can merge multiple static libraries into a single library. Just link them together to produce a new .lib file (on Windows), or explode them then re-archive (on Linux)
Originally Posted by Dae