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 10-07-2002, 10:50 AM   #1
aizkorri
Member
 
Registered: Feb 2002
Location: Basque Country
Distribution: Fedora 14, Ubuntu 14.04
Posts: 434
Blog Entries: 1

Rep: Reputation: 55
linux dynamic libraries


I want to create Makefile that builds a .so library, but I only find examples that create .a libraries. So,
Does someone of you know which are the main differences between a .so and a .a library? Are they the same thing?
thanks.
cheers,
Aizkorri.
 
Old 10-07-2002, 01:52 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 121Reputation: 121
Take a look at this example that builds a shared object and uses that so to build an executable.

$ cat loadtest.c
Code:
#include <stdio.h>

#include "test.h"

main()
{
   test();
}
$ cat test.c
Code:
#include <stdio.h>
#include "test.h"

void test()
{
   printf("Hello dude");
}
$ cat test.h
Code:
void test();

$ cat makefile
Code:
all:	testme

test.o:	test.h
	gcc -c test.c

libtest.so:	test.o
	gcc -shared -o libtest.so test.o

loadtest.o:	
	gcc -c loadtest.c

testme:	loadtest.o libtest.so
	gcc -o testme loadtest.o -L. -ltest 

clean:
	rm -f *.o libtest.so testme
 
Old 10-08-2002, 06:44 AM   #3
aizkorri
Member
 
Registered: Feb 2002
Location: Basque Country
Distribution: Fedora 14, Ubuntu 14.04
Posts: 434

Original Poster
Blog Entries: 1

Rep: Reputation: 55
Thanks a lot, now I have a little idea on how to build a .so, but I'm getting this output when doing "make" and ./testme:

> ls

>loadtest.c Makefile test.c test.h

>make

>gcc -c loadtest.c
>gcc -c test.c
>gcc -shared -o libtest.so test.o
>gcc -o testme loadtest.o -L. -ltest

>ls

>libtest.so loadtest.c loadtest.o Makefile test.c test.h testme >test.o

>./testme

>./testme: error while loading shared libraries: libtest.so: cannot >open shared object file: No such file or directory

But libtest.so it there!?!?

Do you know what is wrong?. (I think the code you gave me is ok)
cheers,
Aizkorri.
 
Old 10-08-2002, 09:55 AM   #4
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 121Reputation: 121
The dynamic linker cannot find your shared object. You either need to put the directory in /etc/ld.so.conf and run ldconfig, or modify you LD_LIBRARY_PATH environment variable.

Since you are just testing I recommend the env variable.

Code:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/shared/object
 
Old 10-09-2002, 03:26 AM   #5
aizkorri
Member
 
Registered: Feb 2002
Location: Basque Country
Distribution: Fedora 14, Ubuntu 14.04
Posts: 434

Original Poster
Blog Entries: 1

Rep: Reputation: 55
Thank you, now it's working.
 
  


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
ar counterpart for dynamic share libraries ? colmmagoo Linux - Software 0 08-06-2004 02:36 PM
Dynamic partitions and linux FedoraNoob Linux - Hardware 1 06-18-2004 11:18 AM
Dynamic link libraries eshwar_ind Programming 1 05-09-2004 11:02 PM
Linux Version of Dynamic Link Libraries paul_eniki Programming 4 02-05-2004 09:25 AM
Mixing Shared and Dynamic Libraries linuxeco Programming 1 02-02-2003 09:04 PM

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

All times are GMT -5. The time now is 06:08 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration