Compiled C++ program raises "cannot open shared object file" on another system though the file is present
Asked Answered
H

6

8

I wrote a tiny program that requires some libraries including libboost_filesystem, libboost_program_options and libcurl.

I compiled it on my home machine and took the binary to my computer at work to test it there. But there it gives the following error message when I try to start the program:

error while loading shared libraries:
libboost_filesystem.so.1.42.0: cannot
open shared object file

But when I search for this file I see that it exists in: /usr/lib/libboost_filesystem.so.1.42.0

Did I something wrong during the compilation / linking of my program? If yes what do I have to do to make it work on other machines?

Hypethral answered 2/11, 2010 at 13:46 Comment(4)
I often find that ldd can help me find out what's wrong. What does ldd ./your_executable say?Sandry
From what you have said, it looks like it should be working. There may be a 32 bit vs 64 bit conflict. Try running file ./your_executable and file /usr/lib/libboost_filesystem.so.1.42.0 to check that the architectures match :)Sandry
wow you are right. the program is built as 32bit and the library present is 64bitHypethral
well, mixing 32bit app and 64bit os doesn't work that well :)Excipient
B
7

First, try to issue ldconfig -p | grep libboost_filesystem.so in a console to make sure the library is in your ld cache.

If it is not, you may need to add a file with a name like boost.conf to your /etc/ld.so.conf.d directory. This file should contain a path to your boost libraries. Then run sudo ldconfig to update your system's ld cache.

Hope this will help...

Barley answered 2/11, 2010 at 14:35 Comment(0)
S
1

Did you compile the shared binaries of boost and provided them to the user?

Often boost can be used without any binary/shared to provide. But if you use, for example, boost::filesystem, you'll have to build the binaries, as lib or shared object, and make sure it's available to the final executable shared binary search path.

You can find an explaination and more details in the boost documentation. Here is the linux version : http://www.boost.org/doc/libs/1_44_0/more/getting_started/unix-variants.html

From this page :

Most Boost libraries are header-only: they consist entirely of header files containing templates and inline functions, and require no separately-compiled library binaries or special treatment when linking.

...

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
Sebiferous answered 2/11, 2010 at 13:50 Comment(2)
Could you explain this with more details please? Or lead me to some resource? I am fairly new to linux development and do not know much about it.Hypethral
I'm adding a link to more precise documentation about that. Done.Sebiferous
E
1

Looks like you need to statically link the library. Here's a good explanation. Boost static linking

Epidaurus answered 2/11, 2010 at 13:53 Comment(1)
ok but if I link them statically won't I lose the benefit of having dependencies to shared libraries? I thought that would be the "standard" way under linuxHypethral
E
1

Did you link against the same version of the boost_filesystem library? Depending on how you compile your application, it requires the very same version of the library to be present.

You could try to check for what your application actually looks for with:

ldd <your app name>

Probably check your LD_LIBRARY_PATH environment variable as well.

Excipient answered 2/11, 2010 at 13:57 Comment(1)
lld gave me libboost_filesystem.so.1.42.0 => not found libboost_program_options.so.1.42.0 => not found libboost_system.so.1.42.0 => not foundHypethral
S
1

Could you make sure that /usr/lib/libboost_filesystem.so.1.42.0 is not a dead link ?

Scissor answered 2/11, 2010 at 14:5 Comment(0)
H
1

is /usr/lib in your LD_LIBRARY_PATH environment variable?

Hefty answered 2/11, 2010 at 19:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.