LinuxQuestions.org
Help answer threads with 0 replies.
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 11-19-2014, 11:55 PM   #1
nagendrar
Member
 
Registered: Apr 2008
Location: HYD, INDIA.
Posts: 154

Rep: Reputation: 15
Shared lib is compiling without any static lib link (even it has 3rd party APIs)


Hi,
I am preparing my custom shared library (.so) file by including APIs of other static library (net-snmp library).

Here my problem:
My custom shared library is compiling with/without library (net-snmp library) linking.
But at the time of execution, failed to load my custom library and giving undefined "syslog_handler" symbol error in both cases. (This symbol is existed in net-snmp static library).

Please help me to find out the reason for compiling without linking any library & to find out the reason for loading problem even though after static library link.

-regards
Nagendra Rednam
 
Old 11-20-2014, 01:59 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
When you link the shared object, use this linker option: -Wl,--no-undefined

If you have a non-working executable, try to examine the problem with commands like these:
Code:
readelf -d problematic_executable
ldd problematic_executable
 
Old 11-20-2014, 03:42 AM   #3
nagendrar
Member
 
Registered: Apr 2008
Location: HYD, INDIA.
Posts: 154

Original Poster
Rep: Reputation: 15
Thanks for Reply.

After adding "-Wl,--no-undefined" option at shared library compilation by linking with static lib (net-snmp lib), I am getting "libnetsnmptrapd.a(snmptrapd_handlers.o): relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC libnetsnmptrapd.a: could not read symbols: Bad value" error message.Even though we built the static libraries (net-snmp lib) on 64bit machine only.

If we did same thing(netsnmp static library link t executeble) for a executable it successfully linked (and running) but failed to link (net-snmp static lib) for shared-library.

My machine is 64 bit Linux machine .

Please help me to solve this problem.

-regards
Nagendra Rednam
 
Old 11-20-2014, 03:56 AM   #4
nagendrar
Member
 
Registered: Apr 2008
Location: HYD, INDIA.
Posts: 154

Original Poster
Rep: Reputation: 15
Reason for same problem is explained in following link
http://stackoverflow.com/questions/1...-linking-error



-regards
Nagendra Rednam
 
Old 11-20-2014, 04:03 AM   #5
nagendrar
Member
 
Registered: Apr 2008
Location: HYD, INDIA.
Posts: 154

Original Poster
Rep: Reputation: 15
Following gives the resolution:
http://www.linuxquestions.org/questi...ls-4175517572/

-regards
Nagendra Rednam
 
Old 11-20-2014, 05:15 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
> libnetsnmptrapd.a(snmptrapd_handlers.o): relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC libnetsnmptrapd.a

Very true, shared lib can only be built from relocatable objects (-fPIC flag at compilation)

PS: The is a special program called libtool especially for handling shared (and static) libraries.
 
  


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
Attaching lib.so while creating static lib barunparichha Linux - Software 1 07-16-2011 03:50 PM
Static Lib subramani Programming 1 04-25-2011 12:11 AM
" Warning: This system can not link to static lib archive ... " asdf989 Programming 3 01-28-2010 04:48 PM
3rd party repos / compiling klapaucius Slackware 6 07-20-2008 05:13 PM
Making a static lib from objects + static libs kovacsp Programming 2 12-19-2007 12:53 PM

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

All times are GMT -5. The time now is 01:20 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
Open Source Consulting | Domain Registration