NotInControl
NotInControl

Reputation: 31

Cannot find shared libraries on target after Cross-Compiling, Ubuntu to Beaglebone

I am working on a vision project using a beaglebone white. I am using an i686 machine running Ubuntu 12.04 LTS and the eclipse IDE with CDT plugin as my development machine. My beaglebone is running the latest Angstrom distro provided from beaglebone.org. My question has to do with general cross-compiling methodologies.

My program uses OpenCV and Curl c++ libraries.

So far on my host machine I have downloaded the latest OpenCV and Curl libraries and have crossed compiled them for the arm-linux architecture.

My test program compiles without errors on my development pc and generates an executable.

I use SCP to transfer the executable to the beaglebone over ethernet, and when I run my program I get the following error on the beaglebone:

"error while loading shared libraries: libopencv_core.so.3.0: cannot open shared object file: No such file or directory"

On the host computer OpenCV and Curl source and libraries are in two separate locations.

For OpenCV I used:

sudo cmake -DSOFTFP=ON -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../..
sudo make
sudo make install

which creates arm-compiled version of OpenCV in the /home/OpenCVArm/opencv/platforms/linux/build_hardfp/install/ on my host.

For Curl I used:

sudo ./configure --host=arm-linux-gnueabi --build=i686-linux CFLAGS='-Os' --with-ssl=/usr/bin/openssl --enable-smtp
sudo make
sudo make install

which creates the Arm compiled curl library is in /usr/local/ on the host.

to link all the libraries in my program I use the following script in Eclipse:

arm-linux-gnueabi-g++ -L/usr/local/lib -L/home/OpenCVArm/opencv/platforms/linux/build_hardfp/install/lib -L/usr/arm-linux-gnueabi/lib -o "HelloWorlTest"  ./src/HelloWorlTest.o   -lopencv_highgui -lopencv_core -lopencv_imgproc -lcurl

My questions are:

  1. It appears I can get rid of my shared library error on the bone, by copying the appropriate libraries from my arm-compiled versions on the host to the target. So the target needs a copy of all libraries as well in order for the program to run. Since these are shared libraries and they are not included in the final executable, why do I need to compile the source for the target platform on the host in order to make the host linker happy? It appears the arm-compiled versions of the shared libraries are never used on the host. I initially thought it was so they would be packaged with the executable, but that is obviously incorrect.

  2. If I copy the needed shared libraries from the host to the directory where the executable is stored on the target, the program still fails to find the shared libraries. The program will only run if I place a copy of the needed .so files in the /usr/lib/ folder on the target. What folders are searched for shared libraries when running an executable? Why won't it find shared libraries within its own local folder?

  3. As I add more libraries to my project, what is the best way to manage them, and get them on the target. I really do not want to download the source on my host, cross-compile for arm, and then sift through all the libraries generated to only transfer the .so files I need on the bone. What is the proper way to provided the target with only the needed libraries for the executable? Is there a tool/plugin to manage or make this process automated?

  4. How can I determine what are the required libraries irrespective of all the libraries I added to the eclipse linker?

  5. If I wanted to tell eclipse to not use shared libraries how do I change the compile scripts for OpenCV, Curl, and modify eclipse so that static libraries are used instead?

  6. When doing embedded programming, and cross-compiling is it more typical to use shared libraries or static libraries?

Thanks for the help.

Upvotes: 2

Views: 5457

Answers (1)

Richard Pennington
Richard Pennington

Reputation: 19965

  1. You are just making the linker happy having the shared library on the host. It looks in the shared libraries to make sure the symbols your program uses are resolved. They are not linked in or used for anything else.
  2. /lib and /usr/lib are the usual place to find shared libraries. You can add directories to the dynamic loader's search path by defining the LD_LIBRARY_PATH environment variable:

    setenv LD_LIBRARY_PATH /home/me/lib:/home/me/lib2

  3. I have no clue if there is some kind of tool/plugin for this. I use scp. ;-)
  4. The ldd command will tell you what shared libraries an executable uses.
  5. Good question. I've never built them. Often packages will build both shared and static libraries.
  6. I don't know if is more typical to use shared libraries or not. I generally use static libraries. In my ELLCC cross compiler project. I have used ELLCC to build itself. The resulting statically linked executables were actually smaller than the gcc compiled executable that uses shared libraries. Of course that is with an entirely different set of C++ and C standard libraries.

Upvotes: 2

Related Questions