I am building a unix c++ program that calls boost, but when i try to run it i get
error while loading shared libraries: libboost_filesystem.so.1.42.0: cannot open shared object file: No such file or directory.
I didn't use to get this error before ( even though i was already calling boost ) , though i don't know what triggered the change. Anyway - doing ldd on the binary, it indeed shows that the library is missing.
I guess the solution would be to add in the LD_LIBRARY_PATH a link to the library containing the .so file - but i can't find it. Where should it be? Is this the right solution?
Note that i don't have sudo privelages on my computer, so i can only change user settings - And also that i'm a linux newb so please try to explain simply...
I think the problem is that you have linked to a very specific version of Boost (1.42.0 in this case). This worked as long as Boost existed in that exact version on your system, but as soon as an update to a more recent version of Boost happened, the linked library could no longer be found.
You might want to adjust your Makefile to link to a more generic version of libboost_filesystem.so.
Related
Hello when I build my wxWidgets GUI application on Linux the build goes fine. I can even run it and it works as expected. When I copy the binary to another Ubuntu computer and try to run it I get this error:
./app2: error while loading shared libraries: libwx_baseu_unofficial-3.1.so.0: cannot open shared object file: No such file or directory
Even when copying the lib across I still get an issue. Why is it dependent on external libraries and how can I solve this problem as I don't want other computers to require this library to be installed? I suppose I could try to statically link it but others recommend you do not do this.
You need to install the entire wxWidgets runtime/shared library on any machine you copy your binary onto. This is the whole point of using aptitude -- each binary package has a list of dependencies that get installed along with it.
To overcome this you need to statically link your binary. You are currently using shared linking, which relies on, as you note, external libraries. ".so" means Shared Object. You'll have to link against static archive libraries, often ending in ".a". Typically development packages provided by aptitude do not provide these, so you will probably have to compile wxWidgets yourself to provide these. Just make sure to also statically link and compile all of wxWidgets downstream dependencies as well. This is the major downside of static linking.
You can also look into something like Holy Build Box.
I want to use a Qt app on a tiny210 device.
I installed Qt ( qt-everywhere-opensource-src.4.8.5 ) downloaded from here. I managed to compile a simple application for use on tiny210. The problem is that now when I try to run the app on the device, I get the following errors:
libc.so.6: version 'GLIBC_2.15' not found (required by libQtCore.so.4)
libc.so.6: version 'GLIBC_2.15' not found (required by libQtNetwork.so.4)
There is a libc.so.6 in /lib/ on the target device, but it is version 2.11.
I should mention that before getting those errors I also got errors for not having libQtCore.so.4, libQtNetwork.so.4 and libQtGui.so.4. I fixed those errors just by copying the compiled libraries from my host PC to the device.
First question is: Would there have been a better way to provide the needed libraries, or copying them is fine?
Second question is: How can I get over the errors mentioned above?
EDIT : I've read something about building it static, but I am not sure how, and what are the downsides of this.
EDIT2 : I managed to get over the above errors thanks to artless noise's answer, but now I get: error loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory.
The issue is the cross-compiler (apt-get install gcc-arm-linux-gnueabi) is ARM based and this cross compiler has a newer glibc than on the ARM device. You can copy the libc from the cross compiler directory to your ARM device. I suggest testing with LD_LIBRARY_PATH, before updating the main libraries. Use ls /var/lib/dpkg/info/*arm-linux*.list to see most packages related to the ARM compiler. You can use grep to figure out where the libraries are (or fancier things like apt-file, etc).
Crosstool-ng has a populate script, but I dont see it in the Ubuntu packages; it is perfect for your issue. If it is present on your Debian version, I would use it.
The glibc 2.15 is backwards compatible with the glibc 2.11 which is currently on your system. Issues may arise if the compiler was configured with different options (different ABI); however if this is the case, you will have many issues with your built Qt besides the library. In this case, you need to find a better compiler which fits your root filesystem.
So to be clear, on the target
mkdir /lib/staging
cp libc.so-2.15 /lib/staging
cd /lib/staging
ln -s libc.so-2.15 libc.so
LD_LIBRARY_PATH=/lib/staging ls # test the library
You may have to copy additional libraries, such as pthread, resolv, rt, crypt, etc. The files are probably in a directory like sysroot/lib. You can copy the whole directory to the /lib/staging to test it. If the above ls functions, then the compilers should be ABI compatible. If you have a crash or not an executable, then the compiler and rootfs may not be compatible.
Would there have been a better way to provide the needed libraries, or copying them is fine?
Copying may be fine as per above. If it is not fine, then either the compiler or the root filesystem must be updated.
How can I get over the errors mentioned above?
Try the above method. As well, you maybe able to leave your root filesystem alone. Set-up a shadow directory and use chroot to run the Qt application with the copied files as another solution. To test this, make a very simple program and put it along the compiler libraries in a test directory, say /lib/staging as above. Then the test code can be run like,
$ LD_LIBRARY_PATH=/lib/staging ./hello_world
If this doesn't work, your compiler and the ARM file system/OS are not compatible. No library magic will help.
I've read something about building it static, but I am not sure how, and what are the downsides of this.
See Linux static linking is dead. I understand this seems like a solution. However, if the compiler is wrong, this won't help. The calling convention between OS, libraries and what registers are saved by the OS will be implicit in the compiled code. You may have to rebuild Qt with -softfp, etc.
I upgraded my system (to ubuntu 13.04) and somewhere in the process gcc broke :-( I'm getting this exception when trying to compile something:
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/bin/as:
error while loading shared libraries:
libopcodes-2.22-system.so: cannot open shared object file: No such file or directory
Actually libopcodes-2.22-system.so does not exist, BUT libopcodes-2.23.2-system.so does.
If i symlink from 2.22 to 2.23 gcc fails with just another library.
So for some reason it is looking for the wrong version. I wildly tried to solve it by reinstalling gcc, binutils, libc6 etc., but the problem still exists.
How can i tell gcc to use the correct shared library version? / Where does gcc gets the information which shared libraries to use?
Thx
Thanks guys, your comments made me look at the right place.
This path made me suspicious:
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/bin/as
I thought it must be a symlink to /usr/bin/as, but it exposed that /usr/x86_64-linux-gnu/bin was a complete copy of /usr/bin - not up to date and therefore with incorrectly linked binaries. I have no idea why a copy of the whole bin directory was there and was used by gcc in favor of /usr/bin.
The compiler is running fine after /usr/x86_64-linux-gnu was removed.
Edit: Better check comments before doing the same.
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?
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...
Looks like you need to statically link the library. Here's a good explanation. Boost static linking
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.
Could you make sure that /usr/lib/libboost_filesystem.so.1.42.0 is not a dead link ?
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
is /usr/lib in your LD_LIBRARY_PATH environment variable?
I've been trying to get the boost library working with Code::Blocks and am having some trouble.
When I first tried to get boost, all I did was download the latest zip file and extract it into the CodeBlocks folder. Then I set the compiler settings to look in the boost folder. This allowed me to compile, but not to link. I then read the BoostWindowsQuickReference. I removed everything I had related to boost from my machine, and started fresh.
I followed the instructions step by step, and the only thing that didn't go exactly as the instructions said was that the install-proper folder with the include\boost inside of it was in C: and not my CodeBlocks folder. So I simply copied it (just in case for some reason it needed to be there) to the CodeBlocks folder, which I thought odd because I already had a boost_1_40_0 folder there from downloading the .zip.
I then tried to compile a program and it came up with the exact same error. Then I realized that I forgot to put in the link library (Ex: boost_regex-mgw44-mt-1_40.lib). Now I get
error: ld.exe||cannot find -lboost_regex-mgw44-mt-1_40.lib|
I have a few questions:
Obviously, what am I doing wrong?
Will I need to put in a link library every time I want to use a boost facility (everything is separated into different files, there isn't just one big project.)
Was it necessary to build the library with the boost-jam or could I have just extracted it and used it? (Probably a dumb question, but a small seed of doubt was planted when I got the exact same error.)
Should I try nuwen's MinGW Distro? (Would it make things any easier?)
If any clarification is needed I'd be happy to do so. Thanks.
Edit: and now I can't compile regular programs. So I'm just starting fresh again.
1, it should be -lboost_regex-mgw44-mt-1_40
2, Read the document, most boost library doesn't require to link library
3,4, You should compile it yourself, or try nuwen's MinGW ( I'd installed it and it worked fine )
BoostPro has Windows binaries available for the Boost libraries. If you download just the Boost sources, you will have to compile it, if you are using any of the libraries that are not header-only (such as boost regex). The BoostPro binaries will allow you to link to these without having to build anything.
On Windows it doesn't really matter where you "install" Boost to. Just get the .7z, compile using bjam.exe and pass it the options you need. It will create a folder called "bin.v2" and put the resulting libs in there. In Code::Blocks, all you need to do is edit the project options and point the search path to boost_1_40_0\boost and manually input the libraries to link against (those from bin.v2). It should just work then.
Do not use a precompiled Boost library.