I just downloaded Boost because I need the precise floating-point arithmetic found in cpp_dec_float.hpp; I looked around a lot for other options, and couldn't find a good alternative.
I spent a while figuring out how to install bcp, and now I've finally installed all of it. I ran bcp to copy the cpp_dec_float.hpp file into my project, and lo and behold! Now I have a 9.5 MB Boost folder sitting in my C++ application directory. This will not be acceptable for my purposes.
Is there a way I can only install cpp_dec_float library without the rest of the multiprecision part? If not, does anyone know of a lightweight (VERY important!), fast, maintained and (at least relatively) recent library for arbitrary-precision numbers?
You can download Boost not to your application directory. Usually you install Boost for use with all projects by all users. Boost.Multiprecision is a header-only library, you only need its headers.
If you need to reduce your space that much, you can try to do the following (I did not test it).
Follow standard steps from Boost installation:
Download Boost sources, say, to folder my_boost
cd my_boost; mkdir build
Run ./bootstrap (will create a bjam executable for your platform)
Then ask Boost to configure for specific set of libraries only. Since the library multiprecision depends on some others, you might need to specify them all:
bjam --build-dir=build --with-multiprecicsion --with-utility --with-type_traits install
You are guaranteed that unrelated libraries will not be built. I am not so sure that unrelated header files will not be copied to Boost include library.
See "bjam --help" for more options.
i've also noticed that bcp copies more files than it should. my strategy: get it compiling, then spend 10 minutes removing stuff from your boost dir, checking to see if it still compiles each time. :)
Related
CMake FetchContent is a great way to manage build dependencies, by integration the dependency into your build and build it from source along with your own sources.
I would like to do this with Boost, too. I am encouraged by the fact that CMake support for Boost is steadily improving.
Of course since Boost is a large package, and one rarely uses all Boost libraries in a project, it would be rather wasteful to pull the entire Boost sources into one's own build. Given the modularity of the Boost project, using git submodules, it would be much more intelligent and efficient to only fetch the sources for the libraries actually used, and FetchContent supports this via its GIT_SUBMODULES option.
However, this doesn't seem to cater for dependencies between the Boost libraries. Do I need to handle this manually, or is there a more intelligent solution?
Furthermore, how do I control installation in this scenario? Many Boost libraries are header-only, and I don't want the headers included in my installation, since I'm only using them for my build. Is there a way to tell CMake that I don't want anything installed from what I fetch with FetchContent?
I have read Craig Scott's book, and of course the CMake documentation, but there's not much information about this sort of problem.
But maybe I'm trying something that I shouldn't be doing. Have others tried this, and can show me how it's done properly?
I am using MinGW from the command line and I want to derterime which boost libraries I have available...particularly I need to do some discrete graphs and threading...
When I try
include <boost/thread.hpp>
I get a no such file or directory.
So a better question might be how do I install boost to my C++ compiler
You can get a tarball of the latest Boost release here:
http://sourceforge.net/projects/boost/files/boost/1.47.0/
Untar/zip (depending on your platform), and you'll find a binary named 'bjam' or 'bjam.exe'. Bjam is the Boost extension of the Perforce (J)ust (A)nother (M)ake build system. If you run bjam from inside the directory that you just unpacked, then it should automagically configure the build and run it. After that I think you type 'bjam install' (with the proper privs) and it puts the boost includes in the most likely place that your compile will look for them and the object code in the most likely place that your linker will look for them. OR... bjam will produce an error message (which will hopefully be helpful) and halt. The whole procedure is pretty brainless once you've done it once. Things get complicated if you want to use MPI or some of the more advanced features of Boost.Serialize (not really, you just need zlib-devel and something else, I forget what).
HTH!
I have just downloaded the boost libraries from the boost website and extracted them to my desktop. I was hoping to just have a quick look at them and have them installed on my machine and perhaps use them in the future when I am more accustomed to C++.
When I extracted it, I was confused with all of the extracted files. There is all of the headers in the boost directory but tutorials mention running bootstrap.bat (I'm using Windows).
So I am asking this: do I simply extract the headers to my compilers include directory like normal to get boost up and running or do I need to do something else?
As I understand it from searching about, apparently "most" of boost is just templates and can be used simply by including the headers, but what about the rest?
Am I totally barking up the wrong tree?
Thanks for any help
Since you mentioned you run Windows, take a look at this automated installer:
► http://www.boostpro.com/download/
Also, some general advice:
do I simply extract the headers to my compilers include directory
No! Do not pollute your compiler's includes with third-party includes; make a separate directory specifically for a particular library. You'll then need to tell your specific IDE in what directory it can find the library headers.
I usually use boostpro's installer, it is less work. I vaguely remember having to set up the BOOST_ROOT environment variable on one of my systems to use it.
The libraries that contained compiled source should be included in the installer.
If you don't use the installer (or don't set up your build correctly), and try to use the libraries that need it you will likely get some linker errors when you try and compile your program. Usually if you take those linker errors and plop them in google it tells you pretty quick which libraries you need to include in your build system. I use CMake for that and have been very happy..
Just add the root boost directory to include paths of your compiler/IDE (so if you have Boost extracted to C:\Boost, the compiler will use that path, not C:\Boost\boost).
Don't do any copying of the boost folder to your compiler's include directory, because it may make upgrading Boost harder in the future.
Also if you plan to use any of boost's compiled libraries, add Boost's lib directory to compiler's library search paths. Configuring the compiling step is a matter of putting the right toolset parameter to boost's build tool. If you have your command line environment configured properly, bootstrap should run and compile the builder without any problems, and the Boost builder should properly detect your toolset, so no parameters will be necessary.
As you do such configuration only once every time you do a clean install of your favorite compiler, it's not as hard or daunting as it seems.
I'm not new in C++ although I'm new in Linux. I'm using CMake to precompile a cross-platform game engine with some third-party components, but I have a lot of doubts about using libraries. My question is how to work with third-party libraries and where to put them. Apt installs libs in their official place (/usr/local, /usr/lib/ ..) but I develop in Windows using local libs that are in a folder in my project dir.
Also, I need a good tutorial to know the rules of how libraries work. For example: when trying to compile my project, luabind is asking for liblua.s0.1, but AFAIK there is no way to generate this library with the source provided by Lua (at least doing make, make install).
I know, this question is fuzzy but I haven't enough experience to be more concise.
Update: After reading some answers, a more concise question is the following. If I install all third-party libraries, how can I distribute my program? How do I manage dependencies without using a large readme?
Where to put libraries
The best solution is to use your Linux distribution's packaging system (apt-get, yum, or similar) to install libraries from distro-provided packages wherever possible.
If the distro's packaged libraries aren't of a recent enough version, or if you need some nonstandard build options, or if you need a library that your distro doesn't provide, then you can build and install it yourself. You have two main options for where to put the library:
/usr/local (libraries under /usr/local/lib, headers under /usr/local/include). This installs the libraries systemwide and is probably the simplest solution, since you should then be able to build against them without taking any extra steps. Do NOT install libraries directly under /usr, since that will interfere with your distro's packaging system.
Under your project directory, as you did under Windows. This has the advantages of not requiring root access and not making systemwide changes, but you'll have to update your project's include paths and library paths, and you'll have to put any shared library files someplace where the dynamic linker can find them (using LD_LIBRARY_PATH or ld.so.conf - see the link for more details).
How libraries work
See David A. Wheeler's excellent Programming Library HOWTO. I'd recommend reading that then posting any specific questions as new topics.
How to distribute your program
Traditionally, Unix / Linux programs do not include copies of their dependencies. It's instead up to the end user or developer to install those dependencies themselves. This can require a "large README," as you said, but it has a few advantages:
Development libraries can be installed, managed, and updated via the distro's package manager, instead of each source copy having its own set of libraries to track.
There's only one copy of any given library on a system, so there's only one place that needs updating if, for example, a security flaw is found. (For example, consider the chaos that resulted when zlib, a very widely used compression library, was found to have a security flaw, so every application that included an affected version needed to be updated.)
If your program is popular enough (and is open source or at least freely available), then package maintainers for various Linux distributions may want to package it and include it in their distro. Package maintainers really don't like bundled libraries. See, for example, Fedora's page on the topic.
If you're distributing your program to end users, you may want to consider offering a package (.dpkg or .rpm) that they could simply download and install without having to use source. Ideally, from the end user's perspective, the package would be added to distros' repositories (if it's open source or at least freely available) so that users can download it using their package managers (apt-get or yum). This can all get complicated, because of the large number of Linux distros out there, but a Debian/Ubuntu compatible .dpkg and a Red Hat/CentOS/Fedora-compatible .rpm should cover a good percentage of end users. Building packages isn't too hard, and there are good howtos online.
for the first part of your question regarding Windows: there's no real standard place for libraries/headers on Windows, so the easy solution is: create your own. Simply provide a single lib/ and include/ on your system and have all your projects use it (by setting the path in a cmake file that you include everywhere). Put all third party libs in there, for example:
your projects:
d:/projects/projectA
d:/projects/projectB
third party stuff:
d:/api/lib/lua.lib
d:/api/include/lua/....
(you can even use symlinks aka 'directory junctions' if you have different version)
and the corresponding cmake file:
include_directories( d:/api/include )
link_directories( d:/api/lib )
Okay, so this is one of the basic questions and while I myself might not come across very clear on this, here goes:
While building a project, your compiler will need to find the header files of the libraries. The headers must be in the include path.
after compilation is done, the linker will look for the library binaries (files.so or something like that). These must be in the Library path.
That's the basics.
If you have some specific libaries, you can add them to your own project-specific lib/ and include/ directories and add them to the include path and the library path respectively.
Adding these dirs to these paths can be done in many ways, depending upon how you are building the project. I'm sure there is something called LD_PATH involved in all this... But I don't really know the specifics involved with CMake.
A little googling can help you do the above with CMake.
Hope that helps,
jrh
If you are installing the libraries with a package manager, they will probably all end up in the right place. If not you can get the compiler to search for the by providing the an additional search path using the -L <path> flag. You should be able to pass this extra flag to CMake.
Incidentally the -I <path> can be used to add an extra directory to search for include files.
I'm trying to build the boost libraries and others against the os x 10.4u.sdk so I can include them in a project targeting 10.4 upwards.
I'm not entirely sure what to do, am I aiming to put the .dylibs in 10.4.sdk/usr/local/.. or in my default 10.6 /usr/local/.. with support for 10.4?
Any help much appreciated.
Toby.
You need to distribute your libraries to the users, so it doesn't help installing them into your machiine's /usr/local. It's better to just set the linker search path to whatever directory you have the library.
When you distribute an app, you're supposed to put every libraries you use inside the .app bundle (unless you're making a series of apps which share a lot of codes) so that users don't need any installer. So, there's not much to be gained by using the dynamically linked libraries, especially for non-GUI ones like boost. So I would recommend you to make a static library .a and statically link against it.
If you're curious, you can find how to include frameworks in your app here in the SO question.
I don't use a mac, but here's the info i know, combined with the information i gathered on the web. The first thing to know is that most boost libraries do not require any compiled binaries. But i am guessing you know that and want to use other libraries, such as datetime or regex.
To compile boost libraries, the official way is to use a tool named bjam. Download it there (Latest link may be found there).
The command line to use to compile boost libraries using bjam is shown in the following link.
bjam --toolset=darwin --build-type=complete --with-thread
--with-date_time --with-filesystem
--with-regex --with-system architecture=combined
UNTESTED (by me), but all the sources i found suggest this is the right approach.