LinuxQuestions.org
Review your favorite Linux distribution.
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 09-23-2004, 02:14 PM   #1
wiredj
LQ Newbie
 
Registered: Apr 2004
Location: Austin, TX
Distribution: Gentoo
Posts: 19

Rep: Reputation: 0
Forcing dlopen to look at LD_LIBRARY_PATH again


I've run into a situation where I'm developing a plugin for another application, and I need to load up some shared libraries. The problem is one of the shared libraries is commonly not in the user's LD_LIBRARY_PATH. So, I want this plugin to be plug-and-play, and I want to update LD_LIBRARY_PATH (for my app only) if it fails to load the first time. I am successfully setting LD_LIBRARY_PATH, but when I call dlopen again, it fails to find the library. If I give it the full path to the library name, it fails when it tries to find other libraries that are in the folder.

Does anyone know how to make dlopen look at the environment variables again? I've searched high and low and haven't found out

Thanks in advance,
Jon
 
Old 09-24-2004, 06:49 PM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
If your program is a normal ELF executable, then you can (apparantly) set the DT_RUNPATH tag to a list of directories to search for the library. How you do this I do not know.

Personally, I would suggest that you use setenv() to append the additional directories to the LD_LIBRARY_PATH variable, like this:
Code:
char * path = getenv("LD_LIBRARY_PATH");
char buffer[strlen(path)+100];
sprintf(buffer,"%s:%s",path,"/other/path/here");
setenv("LD_LIBRARY_PATH",buffer,1);
Note that you should also test if path is NULL before calling strlen (to avoid a segmentation fault if LD_LIBRARY_PATH is not defined).

Edit: This will only affect your app (and any child processes your app spawns); you should do this before calling dlopen().

Last edited by rjlee; 09-24-2004 at 06:50 PM.
 
Old 09-24-2004, 06:55 PM   #3
wiredj
LQ Newbie
 
Registered: Apr 2004
Location: Austin, TX
Distribution: Gentoo
Posts: 19

Original Poster
Rep: Reputation: 0
Thanks for the info. I'll look into the DT_RUNPATH, see if I can find info about that.

I am actually doing the other part -- appending to LD_LIBRARY_PATH. The problem is that I'm developing a plugin for a regular app. The plugin is "weak-linking" the other libraries because although the library provides some functionality that is better than mine, I have some functionality I can fall back on.

So, the problem with modifying the library path is that the program has already used dlopen to open my shared library Sticky situation, I guess :P

Thanks again for your reply,
Jon
 
  


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
undefined reference to dlopen, dlclose, dlsym and dlerror patrickdepingui Slackware 5 02-14-2010 08:55 AM
Enemy-Territory: dlopen libGL.so.1 failed DaneM Linux - Games 2 11-12-2005 11:41 PM
PAM unable to open dlopen(/lib/security/pam_securetty.so) NavForum Debian 0 07-30-2005 04:10 PM
Dlopen function - UNDEFINED REFERENCE mamthababu Programming 1 07-19-2005 10:20 AM
dlopen in multi-threading environnement yakotey Programming 2 06-30-2005 08:36 AM

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

All times are GMT -5. The time now is 12:50 AM.

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