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 |
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.
|
|
04-23-2004, 07:01 PM
|
#1
|
Member
Registered: Aug 2002
Distribution: Debian
Posts: 540
Rep:
|
Library linking problem
Everything in this post is off the top of my head.
How do I make any program (that I write) look for libraries in the running folder (or any specific one for that matter). Example:
Code:
gcc -O3 -L. -o myprog myprog.c -lzzip
I want to use zzip lib, which I have in the directory it was compiled under (I can't remember if it complains about 'undefined references' or not, but I don't think it does), however when I run it it says something like:
ld: unable to open file libzzip.etc.etc... no such file or directory
How do I make the program use libraries from any path I want?
|
|
|
04-23-2004, 07:46 PM
|
#2
|
Member
Registered: Apr 2004
Posts: 101
Rep:
|
Im' not sure what your problem is but...
gcc -L <the dir path> yourprogram.c
This is the method for using the libraries in
a specific directory
|
|
|
04-24-2004, 12:41 AM
|
#3
|
Member
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251
Rep:
|
i think you might not have named your library as libzzip.so/libzzip.a that is causing this problem
|
|
|
04-24-2004, 09:30 AM
|
#4
|
Member
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895
Rep:
|
If I understand you correctly, I think you are saying that you are not having any problems getting your program to compile, but it complains when you try to run the program?
I haven't worked much with my own libraries in Linux, so this could be wrong, but I think you need to put your path to your .so into /etc/ld.so.conf, and then run ldconfig as root... Obviously, this might cause problems if you want to be able to move your .so around a lot, so it might just be good to put it in a standard lib directory like /usr/lib, or /lib.
|
|
|
04-24-2004, 08:19 PM
|
#5
|
Member
Registered: Aug 2002
Distribution: Debian
Posts: 540
Original Poster
Rep:
|
Quote:
Originally posted by deiussum
I haven't worked much with my own libraries in Linux, so this could be wrong, but I think you need to put your path to your .so into /etc/ld.so.conf, and then run ldconfig as root... Obviously, this might cause problems if you want to be able to move your .so around a lot, so it might just be good to put it in a standard lib directory like /usr/lib, or /lib. [/B]
|
This is what I DON'T want to do.
Quote:
Originally posted by deiussum
If I understand you correctly, I think you are saying that you are not having any problems getting your program to compile, but it complains when you try to run the program?
|
This is what I want.
I'll try what you suggested shishir. I'll get back with you soon!
|
|
|
04-25-2004, 06:17 PM
|
#6
|
Member
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895
Rep:
|
Ok... I'm confused. Are you saying that I am right that you are getting no errors when compiling, but you get errors when you try to run the program? Saying, "This is what I want" makes no sense because I wouldn't think you would WANT errors at all...
|
|
|
04-26-2004, 12:18 AM
|
#7
|
Member
Registered: Nov 2003
Location: Kerala, India
Distribution: Red Hat, Knoppix, Mandrake, FreeBSD
Posts: 231
Rep:
|
this is the problem becoz the GNU linke ld, check the library file to link in l/lib and /usr/lib gnerally and the name of the shared library should be fothe form lib<name>.so.0 or lib<name>.a or similar ... the <name> specifies the name fo the libarary and the when compiling and linking you need give the name as such along with the -l option .. this how it works...
|
|
|
04-26-2004, 02:05 PM
|
#8
|
Member
Registered: Aug 2002
Distribution: Debian
Posts: 540
Original Poster
Rep:
|
Ok Sorry for the confusion! I am bad at explaining things! =P
I have my program that uses libzzip for opening zipped files. It compiles fine when I install libzzip system wide. However I don't want to do this, I want libzzip to reside in the same folder as my application (not system wide). But when I do this, it compiles fine but won't run, and gives an error as such:
ld: unable to open libzzip.so, no such file or directory.
Whats wrong?
|
|
|
04-26-2004, 02:19 PM
|
#9
|
Member
Registered: Aug 2002
Distribution: Debian
Posts: 540
Original Poster
Rep:
|
Ok! I just made a test program. I am not showing the code because it is an empty program, that includes zzip.h and links the library at compile. This is how I compile it:
g++ -L. -O3 -o test test.cpp -lzzip
But when it is run it says:
./test: error while loading shared libraries: libzzip-0.so.10: cannot open shared object file: No such file or directory
Both libzzip.so and libzzip-0.so.10 are in the directory where the program is being run.
|
|
|
04-26-2004, 03:23 PM
|
#10
|
Member
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895
Rep:
|
As I said before, for shared objects, I think you need the directory of your library in /etc/ld.so.conf, and ldconfig run. That doesn't seem desireable for what you want, though. Another option might be to get a static library version of libzzip, and link that instead (libzzip-0.a). Then that library isn't needed at runtime at all. It is compiled right into your executable code instead.
I think I've also seen some references to dynamically loading libraries, but I don't know if that would give you what you need, or how to use that. It might be worth looking into. I think the library I saw was roughly equivalent to the LoadLibrary/GetProcAddress APIs in Win32. If it was, it could be what you are looking for. Unfortunately, I don't remember the name of any of those functions, offhand.
|
|
|
04-26-2004, 11:07 PM
|
#11
|
Member
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251
Rep:
|
try putting the path where your .so is in LD_LIBRARY_PATH..am sure it will work...
cos otherwise you'd have to modify you ld.so.conf to specifty where all you want the loader to look for the .so's
|
|
|
All times are GMT -5. The time now is 03:21 PM.
|
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
|
|