LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-23-2004, 07:01 PM   #1
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
Question 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?
 
Old 04-23-2004, 07:46 PM   #2
gizmo_thunder
Member
 
Registered: Apr 2004
Posts: 101

Rep: Reputation: 15
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
 
Old 04-24-2004, 12:41 AM   #3
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
i think you might not have named your library as libzzip.so/libzzip.a that is causing this problem
 
Old 04-24-2004, 09:30 AM   #4
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
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.
 
Old 04-24-2004, 08:19 PM   #5
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
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!
 
Old 04-25-2004, 06:17 PM   #6
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
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...
 
Old 04-26-2004, 12:18 AM   #7
hiteshmaisheri
Member
 
Registered: Nov 2003
Location: Kerala, India
Distribution: Red Hat, Knoppix, Mandrake, FreeBSD
Posts: 231

Rep: Reputation: 30
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...
 
Old 04-26-2004, 02:05 PM   #8
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
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?
 
Old 04-26-2004, 02:19 PM   #9
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
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.
 
Old 04-26-2004, 03:23 PM   #10
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
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.
 
Old 04-26-2004, 11:07 PM   #11
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Commandline legth problem linking a shared library DavePrince Linux - Software 0 07-20-2005 08:19 AM
Still library linking problem The_Nerd Programming 19 05-20-2004 04:08 PM
linking own library bobby2k3 Programming 2 10-20-2003 10:36 AM
Help Linking Library!! Please!! Musikolo Linux - Software 1 07-24-2003 03:16 PM
linking library simonissa Linux - Software 2 05-21-2003 09:41 AM


All times are GMT -5. The time now is 06:21 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration