[SUMMARY] gcc -- linking static and shared libraries

From: Ashish Nigam <ashishn_at_ntechra.com>
Date: Sat Sep 14 2002 - 18:43:21 EDT
Hi,
I had this problem of working with static library provided in libpcap solaris
version.
I finally was able to build the shared library out of libpcap.a and get it to
work.
I used this command .

ld -G -o libpcap.so  -lsocket -lnsl -lresolv -lc -z allextract -lpcap
-zdefaultextract

Thanks to Casper for providing me this pointer.

Ashish

My original post was

Hi,
This is a follow-up on my previous mail coz I still haven't been able to find
a solution.

Thanks to these people who replied and gave me some pointers..
Casper Dik
Martynas Buozis
Ed Rolison

I can create executable using static library "libpcap.a" and run the code.
Now I have to create a shared library (.so file) which have my own C code
files and also use this static library.
So in a way,I have to add this static library in shared library..
Well, can this be done ????

Now slightly off topic... Has anyone worked on libpcap in solaris..
why we have to work with ".a" file rather than a shared library... In linux,
it creates shared library and there are no issues there.

Thanks
Ashish

*****************************************************************************
**********************

My previous mail was --

Hi,
I have written a small application using libpcap.
libpcap has libpcap.a library file.
My problem is to statically link "libpcap.a" file and also dynamically link
other .so files to create my own .so file.
I use gcc to create .so file.
If I copy "libpcap.a" file in /usr/lib try to generate .so file of my own, I
am successfully able to create one...

I give these parameters to gcc

/opt/sfw/bin/gcc  -I/usr/local/jdk/include -I/usr/local/jdk/include/solaris
-I/opt/libpcap-0.4 -fPIC -s
hared  -fno-gnu-linker -lresolv -lsocket -lnsl -lpcap -o libntechping.so

My problem starts when I use this .so file
It gives me this error when I try to execute my program..

ld.so.1: /usr/bin/../java/bin/../jre/bin/../bin/sparc/native_threads/java:
fatal: relocation error: file
/opt/AssetRadarClient/sharedlib/singleos/libntechping.so: symbol
pcap_lookupdev: referenced symbol not found

It seems that libpcap has not been statically linked..... so what should I
do ....
what parameters should I give to gcc ....

Thanks,
ashish
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Sat Sep 14 18:40:09 2002

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:42:54 EST