LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-27-2010, 04:51 PM   #1
Lobinho
Member
 
Registered: May 2010
Distribution: Ubuntu
Posts: 72

Rep: Reputation: 18
Link shared library against other shared library


Dear all,

I'm trying to solve a link issue. I think that the solution is very simple, but I cannot reach this solution.

Let's start:
I'm trying to build an B.so that uses A.so.
A.so is compiled using C;
B.so is compiled using C++;

Inside "Aso.h" file I'had declared:
Code:
#ifdef __cplusplus
extern "C" {
#endif
int foo(int iFoo_param1, int iFoo_param2, int iFoo_param3);
#ifdef __cplusplus
}
#endif
The makefile is:
Quote:
gcc -Wall -fPIC -c ./src/Aso.c -O3
mv ./*.o ./lib/
gcc -shared -Wl,-soname,libA.so.1 -o ./lib/libA.so.1.0 ./lib/*.o
At this point everything is OK. Using the "nm" command I'm able to see that the foo function is defined with a "T" at the libAso.so.

The problem starts when I try to compile the B.so.
Inside "Bso.h" I have the Aso.h header file included (Aso.h is the same above):
Code:
#include "../include/Aso.h"
The makefile of Bso seems to be right:
Code:
g++ -Wall -fPIC -c ./src/Bso.cpp -O3
mv ./*.o ./lib/
g++ -shared -Wl,-soname,libBso.so.1 -o ./lib/libBso.so.1.0 ./lib/*.o -lAso
There's no error to compile that, this library seems to be compiled correctly, but using the "nm" command the Aso.so functions appear with "U" of undefined.

Trying to build an executable using the Bso.so library, I got this error:
/lib/../lib/libBso.so: undefined reference to `foo(int, int, int)'

I think that to solve this problem it's only link the Aso.so with the .o files generated at the compilation phase of my Bso.
Using the "ldd" command I'm able to see that Bso.so depends on Aso.so, so what am I missing?

I've made some google searches all day, but no success.
Could someone post a tip or a link to help me to solve this issue?

Thanks in advance.

Last edited by Lobinho; 06-01-2010 at 08:29 PM. Reason: problem solved.
 
Old 05-27-2010, 05:25 PM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
Quote:
Originally Posted by Lobinho View Post
At this point everything is OK. Using the "nm" command I'm able to see that the foo function is defined with a "T" at the libAso.so.
I assume that is simply foo, not the mangled name for foo(int,int,int)

Quote:
but using the "nm" command the Aso.so functions appear with "U" of undefined.
I think that is correct. They should be "U". Is foo there as a simple non mangled name? Is it there (also or instead) as a mangled name?

Quote:
undefined reference to `foo(int, int, int)'
The immediate question is how does the linker know it is foo(int,int,int) rather than just foo.

So somewhere in Bso you are declaring foo in C++ code without the extern "C".

Last edited by johnsfine; 05-27-2010 at 05:27 PM.
 
1 members found this post helpful.
Old 05-28-2010, 09:16 AM   #3
Lobinho
Member
 
Registered: May 2010
Distribution: Ubuntu
Posts: 72

Original Poster
Rep: Reputation: 18
Dear johnsfine,

Thanks for your response!
"foo" was appearing as a simple non mangled name:
nm Bso.so
...
00003f24 T _fini
000019ec T _init
U foo
00006d7c b completed.5843
...

You probably will feel angry to me, cause it was a silly error. The real problem was on my links on makefile. I built the first .so and put it into /lib/ dir. So my program was linking with /lib/Bso.so (wich was compiled without "extern "C"" notation).
I was too obsessed trying to solve this issue that I forgot that.

Thanks again for your reply.

At least now I know why C does not accept "overload" functions. xD

If someone have a similar problem, these are some useful links:

http://www.yolinux.com/TUTORIALS/Lib...ndDynamic.html
http://en.wikipedia.org/wiki/Name_mangling
http://developers.sun.com/solaris/articles/mixing.html
 
  


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
unable to link against a 'c' shared library vessper Linux - Software 4 11-09-2009 11:49 AM
ldd reports shared library missing, but library exists on disk athv_gr Linux - Newbie 7 05-13-2009 01:31 PM
gcc link shared library against another shared library qcp Linux - Newbie 1 07-25-2008 12:15 PM
Link shared library in Kdevelop neikinfology Linux - Software 0 07-12-2007 04:35 AM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 05:20 AM


All times are GMT -5. The time now is 02:16 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration