LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-23-2007, 10:21 AM   #1
Nishant Desai
Member
 
Registered: Jul 2006
Posts: 100
Blog Entries: 1

Rep: Reputation: 15
How to load the library file at start up?


Hiii,

I am trying to run my application at the start up time and that application use the shared library file to execute itself.

Now, my application runs at the start up time, but the library file doesn't load and it gives the error that "error in loading the shared library file: No such file found.

In fact, i have put the library file in bot /usr/lib and /lib, so that it can get from anywhere, but it couldnt get it from anywhere.

Instead once my OS loads, this application runs without any problem and there is no problem in loading the shared library file at that time, can anybody please tell me what could be the error?

In fact there is no ld.so.conf file in my /etc and there is no /ldconfig command run on my OS.

Any help will be appreciable.

Thanks,
Nishant
 
Old 02-23-2007, 03:48 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
I guess that library paths are not yet set when your program is run. Looking into your starting scripts should reveal that. I understand, however, that you want to launch the program at the time it is. If so, the only sensible option seems to be to open the library using full path in your program (the path itself may be passed as program parameter). Of course, if you don't want to launch ldconfig or such.
 
Old 02-23-2007, 11:27 PM   #3
Nishant Desai
Member
 
Registered: Jul 2006
Posts: 100

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Quote:
Originally Posted by Mara
I guess that library paths are not yet set when your program is run. Looking into your starting scripts should reveal that. I understand, however, that you want to launch the program at the time it is. If so, the only sensible option seems to be to open the library using full path in your program (the path itself may be passed as program parameter). Of course, if you don't want to launch ldconfig or such.
Hiii Mara,

I think you are right that i have to do the static linking of the shared library file, but what i observe is, there is no reference in the application about the shared library file and the only concern is about the header file, which will be called by shared library file.

So not sure where to link it, either statically.


Thanks,
Nishant
 
Old 02-24-2007, 12:10 AM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Please do the following:

1. Cut and paste the exact error message (if at all possible)

2. Run "ldd" on your executable, and cut/paste the exact output

3. Post the error message and your ldd output back to this thread

This should help us more intelligently troubleshoot the problem.

OK?

Thank you in advvance .. PSM
 
Old 02-25-2007, 11:07 PM   #5
Nishant Desai
Member
 
Registered: Jul 2006
Posts: 100

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Quote:
Originally Posted by paulsm4
Hi -

Please do the following:

1. Cut and paste the exact error message (if at all possible)

2. Run "ldd" on your executable, and cut/paste the exact output

3. Post the error message and your ldd output back to this thread

This should help us more intelligently troubleshoot the problem.

OK?

Thank you in advvance .. PSM
Hiii,

Below is the error I am getting while starting the application on initialisaztion:

-----------------------------------------------------
"/usr/sbin/slave: error in loading shared libraries: libmodbus.so: cannot open shared object file: No such file or directory"
-----------------------------------------------------

I am getting the above error, instead of there is a file inside my /usr/lib/libmodbus.so.

When i tried to run the command "ldd", it showed me that there is no such command, it mean that there is no linking for the library files has been implemented.

Is it necessary to have the ldd or ldconfig for linking the library files? or should i have to do the static binding?

Thanks,
Nishant
 
Old 02-27-2007, 03:44 AM   #6
tread
LQ Newbie
 
Registered: Feb 2007
Posts: 29

Rep: Reputation: 15
The output of ldd is to see if all dependencies are resolved, and how. ldd should be installed by default, in /usr/bin/ldd.

Anyway, how about setting LD_LIBRARY_PATH yourself? Create a script, say startup_nishants_program
Inside that, add the following code:
Code:
#!/bin/bash
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:<path to directory containing your required library>
export LD_LIBRARY_PATH
<path to your executable>
Then make startup_nishants_program executable, and add it to your startup scripts instead of adding your executable directly.
 
Old 02-27-2007, 11:21 PM   #7
Nishant Desai
Member
 
Registered: Jul 2006
Posts: 100

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Quote:
Originally Posted by tread
The output of ldd is to see if all dependencies are resolved, and how. ldd should be installed by default, in /usr/bin/ldd.

Anyway, how about setting LD_LIBRARY_PATH yourself? Create a script, say startup_nishants_program
Inside that, add the following code:
Code:
#!/bin/bash
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:<path to directory containing your required library>
export LD_LIBRARY_PATH
<path to your executable>
Then make startup_nishants_program executable, and add it to your startup scripts instead of adding your executable directly.
Hiii,

Not a bad idea either to create executable of setting LD_LIBRARY_PATH and to put it inside the initscript files, but my dobut is that it still wont load the libraries, because Linux only search for the files which are in the /etc/ld.so.cache and by the way i have already tried to write the setting Library file path inside the rc.sysinit (Which is an initialisation script), but i then also got an error.

Finally what i did is take the ld.so.conf, write the necessary code inside and then generate the ld.so.cache in my desktop linux and then copy it to my ARM Linux's Ramdisk, and it works for me.

Anyways thanks for the good input.

Thanks,
Nishant
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot load .so file from java library path whalesurf Linux - Software 1 07-24-2006 11:43 AM
Americas army and 'Could not load OpenGL library' STARHARVEST Linux - Games 2 12-23-2005 12:35 PM
my slack can't load shared library AnhTuan Slackware 6 10-03-2004 09:27 AM
shared object library won't load (libstdc++) sleepylight Linux - General 4 04-27-2004 04:24 PM
How do you load dynamically a library from C? Hano Programming 4 06-07-2002 03:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration