How do people distrubute boost programs which have binary dependencies on boost modules?

StackOverflow https://stackoverflow.com/questions/23460725

  •  15-07-2023
  •  | 
  •  

Question

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
Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top