I am writing a C++ application that has to read a binary .MAT file. So I need to use libmat and libmex to do this (note I am not using MEX files though). I am also trying to use boost::program_options to handle parsing command line arguments since this is a non-GUI application. I am using CMake to handle my build environment.
The version of boost we are working with is 1.59. However, when I try to link in program_options, CMake is finding the boost::program_options library in with the MATLAB libraries and the MATLAB libraries require boost 1.49. Then when I try to run the compiled application, it crashes because of using headers from 1.59 but the libraries from MATLAB's copies of 1.49. Does anybody have any ideas how I can use the two versions of boost since MATLAB will not work with 1.59 and MATLAB did not include the include files for 1.49.
If your application crashes, it means that sadly 1.49 and 1.59 are not binary compatible, so the only way this can work is that you force your application to use 1.59. There might be two options:
Force CMake to use 1.59 libraries, by setting BOOST_LIBRARYDIR variant to CMake.
Force CMake to use 1.59 libraries, and static versions of them, by additionally setting Boost_USE_STATIC_LIBS.
I don't actually use CMake, and FindBoost.cmake appears to not always be up-to-date, so I'm not 100% sure the static option will work, but give it a try.
Related
I have troubles with building boost libraries.
I am using version 1.55 on OS Win7.
According to documentation and another thread I found switches that work to build boost with zlib support.
I haven't found a way, how to build boost (static or dynamic) libraries with zlib being external dependency, and will be shipped with my application. In that way, any user can build/change his own zlib, as long as the interface is unchanged.
I such thing possible? Does boost support dynamic zlib linkage?
Finally, I was able to solve the problem with the following.
There is a bug in versions 1.55 and above. Building static libraries can be done using older jamfile (1.53).
For the dynamic library, you need to add zlib.cpp to your project and compile.
With dynamic, meaning there is only zlib.dll linked directly to your project.
I have a very basic client/server project that uses boost::asio. It generates two executables, a client and a server.
When I run the client, I get the following:
./client: error while loading shared libraries:
libboost_system.so.1.55.0: cannot open shared object
file: No such file or directory
This means that the program requires the boost_system binary to be loaded dynamically at run-time. This makes sense, as one dependency of boost_asio is boost_system.
What does this mean for the ease of distributing my application to end-users?
1) Do I simply pop my development version of the boost_system binary on my system, which in this case is libboost_system.so.1.55.0? How do I ensure that when the user runs the client, it will find the dynamic archive? Obviously, on my system, even with my boost install it still didn't find the archive.
2) I am building on Linux and thus I have .so binaries. How will #1 change if I try to cross-compile my app for Windows with mingw-w64?
I am brand-spanking new to distributing C++ programs and working with dynamic/shared libraries.
When I compile statically, I get the following warning:
Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
Suggestion:
1) If you use shared libraries, you'll definitely need to include those libraries your program actually uses alone with your executable.
2) Here is a list of the Boost libraries. Your program will require just a subset:
http://www.boost.org/doc/libs/1_49_0/more/getting_started/unix-variants.html
The only Boost libraries that must be built separately are:
Boost.Filesystem
Boost.GraphParallel
Boost.IOStreams
Boost.MPI
Boost.ProgramOptions
Boost.Python (see the Boost.Python build documentation before building and installing it)
Boost.Regex
Boost.Serialization
Boost.Signals
Boost.System
Boost.Thread
Boost.Wave
A few libraries have optional separately-compiled binaries:
Boost.DateTime has a binary component that is only needed if you're using its to_string/from_string or serialization features, or if you're targeting Visual C++ 6.x or Borland.
Boost.Graph also has a binary component that is only needed if you intend to parse GraphViz files. * Boost.Math has binary components for the TR1 and C99 cmath functions.
Boost.Random has a binary component which is only needed if you're using random_device.
Boost.Test can be used in “header-only” or “separately compiled” mode, although separate compilation is recommended for serious use.
Alternatively, you can link your program with static (.a) Boost libraries instead of shared (.so), in which case there will be NO runtime dependencies.
Or you can mix/match shared/statis as you wish.
The choice is yours.
Look at the Boost documentation: b2 Static and Shared libraries
As said, you need to compile boost with the static option, for example
bjam install --toolset=msvc variant=release link=static threading=multi runtime-link=static
You can have more information in this Thread
Do i have static or dynamic boost libraries?
Something to notice, if you do an ldd on your executable, you'll probably notice some runtime dependencies on gcc/libc libraries, even if you compile it in static mode.
That means your client platform has to have those libraries installed. 90% of the time they're there, but it might be more complicated when you compile with the latest version of the compiler and the client has an older one.
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. :)
I'm working on a project written in C++ that uses the Boost Regex library to do some parsing. My problem is, I need to run the program on a remote machine that doesn't have the boost library installed. I also don't have admin access to this computer so I can't just install it myself.
Is there any way to separate out just the Boost Regex library so that I can put it in the same directory as my other code? I tried doing this already by downloading the boost library and separating out all of the unneeded headers and such. I managed to get it to a point where it calmost compiled but it failed at the linking stage.
Is there anything I can do to fix this or will I be forced to rewrite the parsing code?
You can use the Boost.BCP tool to extract a subset of Boost.
include the static library libboost_regex-gcc-1_35.a your list of object files to compile.
1_35 is an older version number on my linux box, you may have a newer library
I'm quite new to using boost and I can't seem to find documentation anywhere on how to distribute your application when using boost?
Many of the libraries are shared libraries, I'm not expecting my users to have boost installed, I'm only using a single library (regex) so is there an easy way to package the regex library with my application without compiling with the static version?
Linux
For binary distribution, I recommend using the distribution's package management, which should take care of any dependencies.
Some commercial apps just use binary blobs and you need to install a version of boost by yourself.
Finding libraries is a bit more difficult on linux. It does not automatically load shared objects from the current directory if they are linked at compile time (as opposed to loading at runtime with dlopen).
You have to use the LD_LIBRARY_PATH env variable or use rpath. Both has it's drawbacks.
Windows
There is no way around including the dlls. The usual approach is to put everything into a directory and zip it up.
Both
To build from source you need the boost sources anyway, so no need to include libraries.
Most libraries in boost are header only anyway, regexp is not one of them. It should be sufficient to include dlls for this module.
In Linux you can check against which shared libs your binary is compiled by using:
ldd binary