Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
06-14-2012, 12:51 AM
|
#1
|
Member
Registered: Sep 2007
Posts: 102
Rep:
|
Not able to link shared library.
Hi all,
I am building my application.I have 10 cpp files and I made one make file to compile those .My problem is that my application is dependent upon some library that i have to put in some directory.
for example i am storing my library as follow
here i am storing 2 libraries
1st in /opt/my_lib_root
2nd in /opt/my_lib_root/my_lib/
but when my application running it showing
error while loading shared libraries: libproduct.so.1: cannot open shared object file: No such file or directory as I am depending upon this library and it is the 1st library.
I know it is not linked properly ,when i am using
export LD_LIBRARY_PATH=/opt/my_lib_root/my_lib/:/opt/my_lib_root/
it is working.
but i don't want to do in mannualy how to mentioned this one during compilation of the project.
During compilation how to do this or is there any solution for these linking error.
Thanks
Last edited by pradiptart; 06-14-2012 at 12:52 AM.
|
|
|
06-14-2012, 03:33 AM
|
#2
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,240
|
this is the normal behavior, it is not an error. A shared object (*.so file) usually located in /usr/lib or /lib and in your case the file is located in another dir, that's why you need to use LD_LIBRARY_PATH. Another solution can be to hardcode the path of that lib into your app. This can be made by linking this lib with full path to your app.
_____________________________________
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
Happy with solution ... mark as SOLVED
(located in the "thread tools")
|
|
|
06-14-2012, 04:36 AM
|
#3
|
Member
Registered: Sep 2007
Posts: 102
Original Poster
Rep:
|
Hi pan64 ,
Thanks for reply.
Quote:
Another solution can be to hardcode the path of that lib into your app. This can be made by linking this lib with full path to your app.
|
can u say how to hardcode this and where.
Thanks
|
|
|
06-14-2012, 04:48 AM
|
#4
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,240
|
do you have a makefile? can you post it?
|
|
|
06-18-2012, 05:24 AM
|
#5
|
Member
Registered: Sep 2007
Posts: 102
Original Poster
Rep:
|
Hi pan64,
I got your point,
I have tried something like -rpath and able to link it and run it but now I got another issue.
The issue is I am creating a RPM of the application so in the spec file only I am deciding where to put the libraries, which is not same as the path I have given during compilation in -rpath so,the problem is when it is running,the path of library is different and it is not running now so can u tell me how to resolve this error ,
as I don't know where the library will be as first compilation done then only the RPM creation done then how i will able to run this applications as library path is different now.
Kindly tell me this is a serious issue I am facing in my project work.
giving an example:
suppose I am working in /root/work/ folder and the makefile is here and all the source is here.all libraries are in /root/work_lib/ that I know during compilation and able to link this library during compilation,and able to run this
but during RPM creation I am deciding where to put the libraries of the RPM and that is different from this /root/work_lib/ and also that is variable depends upon the reqirements of projects ,so how do i able to make this application that will work after the RPM creation.
to this problem I got the old style LD_LIBRARY_PATH environment variable that I have to set in RPM spec file but is that the only one solution is there any other solution to this problem.
Thanks
|
|
|
06-18-2012, 06:28 AM
|
#6
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,240
|
in such cases probably you can write a small shell script to set LD_LIBRARY_PATH and invoke your tool. Also you can use relative path during link: (instead of -L <path> -l <lib> simply write ../lib_dir/libsomething.so). In this case the app will look for the lib in ../lib_dir (which is probably not really good, but you can decide). You can try dynamic loader also to load a library.
_____________________________________
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
Happy with solution ... mark as SOLVED
(located in the "thread tools")
|
|
1 members found this post helpful.
|
06-18-2012, 08:26 AM
|
#7
|
Member
Registered: Sep 2007
Posts: 102
Original Poster
Rep:
|
hi ,
As you told dynamic loader,dlopen() function needs the library path that i can't give during compilation.
The problem is how to use the path that I do not know during compilation ,so I can't do any thing during compilation.
simply I have to build the RPM and then I have to do something by which the application should find the libraries.
The solutions to this problem are as follows
solutions
1.LD_LIBRARY_PATH
2?
3?
I need the other possible ways to do this.kindly tell about that .
Thanks
|
|
|
06-18-2012, 08:33 AM
|
#8
|
Member
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 651
Rep:
|
Why don't you put the library inside a default path, like /usr/lib, /usr/local/lib etc.?
This way all your issues should be solved with no need for rpath and LD_LIBRARY_PATH...
Last edited by 414N; 06-18-2012 at 08:35 AM.
|
|
|
06-18-2012, 08:36 AM
|
#9
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,240
|
Quote:
void *dlopen(const char *filename, int flag);
The function dlopen() loads the dynamic library file named by the null-terminated string filename and returns an opaque "handle" for the dynamic library. If filename is NULL, then the returned handle is for the main program. If filename contains a slash ("/"), then it is interpreted as a (relative or absolute) pathname. Otherwise, the dynamic linker searches for the library
|
If you describe the filename with full path that will be used.
LD_LIBRARY_PATH can be set with a small wrapper script which will look for the lib and set the variable before executing your app. Both can work runtime, so in both cases they can use the path of the installed package.
|
|
|
All times are GMT -5. The time now is 01:25 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|