4

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
  • You can use the static library versions (`.a`) to avoid having external dependencies. Maybe you'll have to recompile boost with some parameters to get them. – Chnossos May 04 '14 at 19:43
  • When I link statically I get `Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking` –  May 04 '14 at 19:49
  • Here's what ant generates: g++ -fexceptions -pthread -std=c++11 -o build/debug/client /eclipse/cppplay/build/debug/obj/client/Client.o -static -I/usr/local/bin/boost -L/usr/local/bin/boost/lib -lboost_system -g –  May 04 '14 at 19:53
  • Maybe [this](http://stackoverflow.com/questions/2725255/create-statically-linked-binary-that-uses-getaddrinfo) can help you. I never encountered this warning before. – Chnossos May 04 '14 at 19:58
  • I already saw that SO question. There's no great answer in the post unfortunately. –  May 04 '14 at 20:13

2 Answers2

2

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

FoggyDay
  • 11,962
  • 4
  • 34
  • 48
  • I already knew all of this. If I compile statically I get the warning mentioned in my question. –  May 04 '14 at 20:12
  • OK. Two additional suggestions: 1) run "ldd" on your executable to see exactly what shared dependencies exist (and how they're resolved on your development PC). 2) test-deploy your executable to a VM (for example, a VBox or VMWare) running a "clean install" of the OS (without your development libraries). 'Hope that helps... – FoggyDay May 04 '14 at 20:49
0

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.

Community
  • 1
  • 1
dau_sama
  • 4,247
  • 2
  • 23
  • 30
  • I already have the static binaries. This question is about runtime dependencies and how to minimize them for end users. I wouldn't have been able to compile if I didn't have the binaries. –  May 04 '14 at 20:11