Amrutha Saseendran
Posts: 13
Joined: Wed Apr 19, 2017 12:10 pm

error loading a shared library in raspberry pi

Thu Aug 10, 2017 1:55 pm

i have cross compiled qt in raspberry pi and now i am trying to implement a shared library in it. i have created a shared library in qt in my laptop and deployed it to raspberry pi. then i created a widget application to call this library and see if it is working. when i tried to run this widget application in raspberry pi it is getting builded sucessfully. but when i tried to run it is showing error as "cannot load shared library"

these are my .pro files of my library and application

.pro of my library

Code: Select all

QT       += widgets

QT       -= gui

TARGET = libforpishared
TEMPLATE = lib

DEFINES += LIBFORPISHARED_LIBRARY

SOURCES += libforpishared.cpp

HEADERS += libforpishared.h\
        libforpishared_global.h

INSTALLS        = target
target.files    = libforpishared
target.path     = /home/pi
.pro of my application

Code: Select all

QT       += core gui widgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = libtryforraspberrypi
TEMPLATE = app


SOURCES += main.cpp\


HEADERS  +=


DEPENDPATH += /home/amruz/libforpishared
INCLUDEPATH += /home/amruz/libforpishared
LIBS += -L/home/amruz/build-libforpishared-Raspberry_Pi-Debug -llibforpishared

INSTALLS        = target
target.files    = libtryforraspberrypi
target.path     = /home/pi

I have deployed the library in raspberry pi. But only .so file is in /home/pi.
How to add the header files of my library to raspberry pi?
I am not sure of that
can anyone guide me in this
thanks in advance

User avatar
topguy
Posts: 6771
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: error loading a shared library in raspberry pi

Sun Aug 13, 2017 1:20 pm

The error "can not load shared library" is not caused by missing header files.
You have to tell the dynamic linker where to look for .so files, normally it only looks in "/usr/lib" and "/usr/local/lib".

If you have a library in the same directory as your binary the easiest way is to use the environment variable LD_LIBRARYPATH to tell the linker to look in more places.

Code: Select all

# add "current directory" to list of places to look for .so files.
export LD_LIBRARYPATH=.
./my_binary

Amrutha Saseendran
Posts: 13
Joined: Wed Apr 19, 2017 12:10 pm

Re: error loading a shared library in raspberry pi

Fri Aug 18, 2017 8:16 am

i tried
export LD_LIBRARYPATH = /home/pi

in raspberry pi
then i ran ./myappplication
still it shows as error while loading sharedlibraries.so.1 :cannot open shared object file: No such file or directory

sorry if i am doing it wrong..
can you please help me out

User avatar
topguy
Posts: 6771
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: error loading a shared library in raspberry pi

Sat Aug 19, 2017 1:54 pm

Exactly where is .so the file located ?

Martin Frezman
Posts: 1009
Joined: Mon Oct 31, 2016 10:05 am

Re: error loading a shared library in raspberry pi

Sat Aug 19, 2017 2:19 pm

Here's the right answer. Follow these steps exactly.

$ mkdir ~/lib
$ export LD_LIBRARY_PATH=~/lib
$ mv -v /path/to/wherever/the/so/file/is_now/whatever.so ~/lib
$ cd /path/to/whever/the/executable/file_is
$ ./program_that_requires_whatever_shared_lib

Note: No spaces are allowed in the "export" command.
If this post appears in the wrong forums category, my apologies.


User avatar
PeterO
Posts: 5964
Joined: Sun Jul 22, 2012 4:14 pm

Re: error loading a shared library in raspberry pi

Fri Aug 25, 2017 10:02 am

Fixed it for you .....
Martin Frezman wrote:
Sat Aug 19, 2017 2:19 pm
Here's just another answer. Follow these steps exactly.

$ mkdir ~/lib
$ export LD_LIBRARY_PATH=~/lib
$ mv -v /path/to/wherever/the/so/file/is_now/whatever.so ~/lib
$ cd /path/to/whever/the/executable/file_is
$ ./program_that_requires_whatever_shared_lib

Note: No spaces are allowed in the "export" command.
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Return to “Beginners”