LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 01-13-2005, 12:32 AM   #1
phoenix_fei
Member
 
Registered: Nov 2004
Location: shanghai
Distribution: worket
Posts: 41

Rep: Reputation: 15
Post dynamically


hello:
I create a libmydll.so file,and now I want to invoke it.But I do not use
"dlopen()" to invoke it. How to invoke ?
thanks
 
Old 01-13-2005, 04:52 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Make sure the directory your .so file is stored is listed in /etc/ld.so.conf. Then (as root) run "ldconfig" and try again.
 
Old 01-14-2005, 12:51 AM   #3
phoenix_fei
Member
 
Registered: Nov 2004
Location: shanghai
Distribution: worket
Posts: 41

Original Poster
Rep: Reputation: 15
hello
I try it ,but not success ???
 
Old 01-14-2005, 05:37 AM   #4
Inunu
LQ Newbie
 
Registered: Jan 2005
Location: NZ
Distribution: Customized MDK 9
Posts: 13

Rep: Reputation: 0
Try following all steps:

1. Compile/link source/object files of your shared library with -fpic, -shared, -Wl,-soname

age.c
Code:
/* one simple function */
int age(){ return 25; }
gcc -fpic -shared -Wl,-soname=libage.so
This gives libage.so, a shared lib.

2. Compile/link your application source with -L and -l

myage.c
Code:
#include <stdio.h>

extern int age(); /* this line is normally in lib's header file */

int main(int argc, char *argv[]){
  printf("My age is %d.\n", age());
  return 0;
}
gcc -L. -lage -o myage myage.c
This gives myage exe file, dynamically linked to libage.so in *current directory*.

3. Run it with LD_LIBRARY_PATH (if libage.so is not going to be in one of listed folders in your /etc/ld.so.conf)

linux/tmp$ LD_LIBRARY_PATH=. ./myage
My age is 25.
 
Old 01-16-2005, 08:01 PM   #5
phoenix_fei
Member
 
Registered: Nov 2004
Location: shanghai
Distribution: worket
Posts: 41

Original Poster
Rep: Reputation: 15
hello,
I try ,but not success .why???
 
Old 01-17-2005, 07:51 PM   #6
phoenix_fei
Member
 
Registered: Nov 2004
Location: shanghai
Distribution: worket
Posts: 41

Original Poster
Rep: Reputation: 15
why

everyone
why not success in my comuter>>>>>
 
  


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
dynamically expanding an array in c++ a1ghagh05t Programming 4 03-07-2004 09:00 PM
getting bind to update dynamically acid_kewpie Linux - Networking 1 11-23-2002 05:28 PM
How do you load dynamically a library from C? Hano Programming 4 06-07-2002 03:04 PM
Compressing a file dynamically xanthium Programming 5 03-22-2002 05:06 PM
dynamically including C modules manjulap Programming 4 03-13-2002 03:00 AM


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