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 05-20-2004, 03:12 PM   #1
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
Still library linking problem


I want my program to use the library mylib.so

mylib.so is in the same folder as my program. I DON'T want mylib.so ANYWHERE else on the system.

How do I make my program use mylib.so?
 
Old 05-20-2004, 03:19 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
gcc -L. myprog.c -o myprog -lmylib

Something like that maybe
 
Old 05-20-2004, 03:24 PM   #3
lyle_s
Member
 
Registered: Jul 2003
Distribution: Slackware
Posts: 392

Rep: Reputation: 55
Given that you have a shared object in /some/nonstandard/place you have two options:
  1. Place /some/nonstandard/place in /etc/ld.so.conf and run the ldconfig command (as root).
  2. Place /some/nonstandard/place in the environment variable LD_LIBRARY_PATH.
For more, see man ld.so.

Lyle
 
Old 05-20-2004, 03:28 PM   #4
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
Quote:
Originally posted by lyle_s
Given that you have a shared object in /some/nonstandard/place you have two options:
  1. Place /some/nonstandard/place in /etc/ld.so.conf and run the ldconfig command (as root).
  2. Place /some/nonstandard/place in the environment variable LD_LIBRARY_PATH.
For more, see man ld.so.
Lyle


Absolutly not! I don't want to use ldconfig in anyway... LD_LIBRARY_PATH would work if I could change it upon startup in my program... except my program doesn't start... so problem.

I have already tried your idea itsme86... It won't compile, and just says "undefined reference" to every function in the lib...

I DO NOT WANT TO CHANGE/EDIT/MODIFY ANY SYSTEM SETTINGS!

Thanks for your help guys. But I am still stuck.
 
Old 05-20-2004, 03:30 PM   #5
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
itsme86's suggestion should work.
 
Old 05-20-2004, 03:31 PM   #6
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
Dynamic linking would be fine if anyone would show me how to do it. But it has to be Windows/Linux compatible, and it has to be easy. You know, not like:

mypt1 = function1;
mypt2 = function2;
mypt3 = function3;
...................

 
Old 05-20-2004, 03:32 PM   #7
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
You could make it a static .a library instead. Another option might be to look at functions like dlopen, dlsym, etc. I haven't used those myself, but a quick look at the man page suggests they are similar to the Win32 API functions LoadLibrary and GetProcAddress...
 
Old 05-20-2004, 03:33 PM   #8
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
Quote:
Originally posted by Mara
itsme86's suggestion should work.
It doesn't. It doesn't complain about not being able to find the library. The linker just complains about all the undefined references....
 
Old 05-20-2004, 03:33 PM   #9
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Quote:
Originally posted by Mara
itsme86's suggestion should work.
It'd work to compile and link, but not to run. When run, it would look for the .so file somewhere in the library paths in /etc/ld.so.conf or $LD_LIBRARY_PATH.
 
Old 05-20-2004, 03:34 PM   #10
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
Quote:
Originally posted by deiussum
You could make it a static .a library instead. Another option might be to look at functions like dlopen, dlsym, etc. I haven't used those myself, but a quick look at the man page suggests they are similar to the Win32 API functions LoadLibrary and GetProcAddress...
Ya... But when I tried this, I had to dlsym EVERY function in the library to a LIST of pointers... this sucked a million times over! So if there is an easy way... sure!
 
Old 05-20-2004, 03:35 PM   #11
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
Quote:
Originally posted by deiussum
It'd work to compile and link, but not to run. When run, it would look for the .so file somewhere in the library paths in /etc/ld.so.conf or $LD_LIBRARY_PATH.
It compiled. But wouldn't link.
 
Old 05-20-2004, 03:39 PM   #12
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
So then make it a static library file so that it isn't needed at all by the final binary.

Either that or you are going to have to put the path to it in ld.so.conf or the LD_LIBRARY_PATH and run ldconfig. I don't think there's any other choice, though I could be mistaken.
 
Old 05-20-2004, 03:40 PM   #13
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Quote:
Originally posted by The_Nerd
It compiled. But wouldn't link.
Is your file called libmylib.so? When you use -llibraryname it expects it to be pre-pended with the lib. Still, even if you get it to link you are going to probably going to run into problems when you try to run the app, as we've been telling you...
 
Old 05-20-2004, 03:40 PM   #14
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
Ok then. Explain to me how Quake3, Heretic II, UT2003, and other such games for linux do the same thing I want to do???
 
Old 05-20-2004, 03:40 PM   #15
lyle_s
Member
 
Registered: Jul 2003
Distribution: Slackware
Posts: 392

Rep: Reputation: 55
How about having users run a bash/shell script that sets LD_LIBRARY_PATH, then uses exec to run the actual program.

This is the approach that the Intel C++ compiler for Linux uses; the icc command is actually a shell script.

Lyle
 
  


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
Commandline legth problem linking a shared library DavePrince Linux - Software 0 07-20-2005 08:19 AM
Library linking problem The_Nerd Programming 10 04-26-2004 11:07 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

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

All times are GMT -5. The time now is 04:09 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