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 09-12-2007, 12:35 AM   #1
UlamTheLucky
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Rep: Reputation: 0
Need help linking shared library g++ 4.1.2 x86_64


Hi, I've spent a lot of time researching this and I am completely out of ideas, so I am hoping someone else can help me.

I am somewhat new to linux shared library programming so bare with me a bit.

relevant details:
g++ 4.1.2
64bit system and libraries

I have some code that creates a shared library for accessing the firebird database through it's api. There is only a single function that is available in the library, and it is appropriately defined with the extern "C" syntax. It compiles fine, the created shared library is cached with ldconfig. But when the program is executed I receive an undefined symbol error.

For clarity I'll add in some simplified code (but probably still a little complex) below. The code wasn't mine, I'm just trying to get it to compile and run in 64 bit.

When the library load is attempted, the undefined symbol is _ZTI9D, (with D being the name of class d) leading me to believe I need to change something about class d but I'm actually clueless. Here's how the classes are laid out.

In file acd.h
Code:
class a {
  public
     static a* getObjectOfA(int& type);
     virtual c* allocC()  
  protected
     a();
     virtual ~a();
  private
    ...
};

class c {
  public
    virtual ~c();
    virtual d* allocD();
    d* allocD(const int& command);
  protected
    c();
    a* A;
  private
};

class d {
  public
    virtual ~d();
  protected
    d();
    c* C;
  private
};

typedef a* (*getAFunc)();
And in file acd_b.h
Code:
class a_b: public a {
  public
    a_b();
    ~a_b();
    
    c* allocC();

  protected
    friend class c_b;
};

class c_b: public c {
  public
    c_b(a_b* A_B);
    ~c_b();

    d* allocD();
 
 protected
    a_b* A_B;
 
    friend class a_b;
    friend class d_b;
}

class d_b: public d {
  public
    d_b(c_b* C_B);
    ~d_b();
  
  protected
    c_b* C_B;
}
and finally in acd_b.cpp:
Code:
class a_b: { 
  lots of code...  
}

class c_b: { 
  lots of code... 
}

class d_b: { 
  lots of code... 
}

extern "C" {

    a* getObjectOfA() {
	return new a_b();
    }

}
The code is compiled with the following flags:
g++ -c -pipe -march=athlon64 -m64 -fPIC -Wall -W -O2 -D_REENTRANT -fPIC -DLINUX -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_PLUGIN -DQT_SHARED -I/usr/lib64/qt/mkspecs/default -I. -I../utility -I../a -I../widget -I. -I/opt/firebird/include -I/usr/lib64/qt/include -Iobjs/ -o objs/a_b.o a_b.cpp

and the shared library subesquently made with:
g++ -L../lib -Wl,-rpath,/usr/lib64/qt/lib -shared -Wl,-rpath,/home/xxx/Prog/drivers -o liba_b.so objs/a_b.o objs/other.o objs/dialog.o objs/crypt.o objs/moc_other.o -L/usr/lib64/qt/lib -ldl -lqt-mt -lpthread

Any help/suggestions would be greatly appreciated - even if it's some links to go read.

Thanks!
 
Old 09-12-2007, 10:05 AM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
If you are linking to Qt, you are obviously excluding something important in your example.

Have you defined your virtual destructors? If they are empty, you can just make them inline and put an empty function block right in the class. They will inline in derived classes, but dynamic destruction will still take the appropriate destructor from the vtable.

Does the code work on other platforms?
ta0kira
 
Old 09-13-2007, 09:22 AM   #3
UlamTheLucky
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks for the reply, Yes, I stripped out the QT stuff for the example I posted, but the code does use QT.

There are functions defined in the .cpp files for the virtual destructors.

I presume the code runs fine on other systems I've seen no indication it does not.

The only thing I am doing that is perhaps really different is that
I am linking against firebird 2.0.x libraries for this code, and the program has to my knowledge only worked with firefird 1.5.x. I did expect some changes will be needed, to fix program functions but I didn't expect it to fail loading the library from the start.

Later today I'm going to try installing the older firebird so I can link against the older libraries. If that works, great, but even then I would like to understand what is causing it to break with the 2.0 libraries.

Last edited by UlamTheLucky; 09-13-2007 at 11:08 AM.
 
Old 09-13-2007, 11:08 AM   #4
UlamTheLucky
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Just tried the compile against firebird 1.5. Same exact problem. so that's not it. - as I suspected would be the case.
 
Old 09-23-2007, 12:01 PM   #5
UlamTheLucky
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Original Poster
Rep: Reputation: 0
I've contacted some other forums, and found some successful compiles on 64bit using the postgresql driver. So I installed postgresql. Recompiled and built that driver, the code is very much the same in structure as I originally posted. And I get the exact same error loading the postgresql driver library. So is there any tricks to creating a shared library with g++ 4.1.x that might be different from earlier versions that is tripping me up?
 
Old 09-23-2007, 04:55 PM   #6
jdiggitydogg
Member
 
Registered: Sep 2007
Posts: 42

Rep: Reputation: 15
it doesn't sound like the compile is the problem, correct? run your app with 'ltrace' and see what happens. try putting your new library's path into the environment variable LD_LIBRARY_PATH and then run your program again.
 
  


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
LINUX - linking archive (static library) with shared (dynamic) library gurkama Programming 5 03-04-2007 11:11 PM
strange linking error -- can not find shared library George2 Programming 1 07-10-2006 11:24 AM
Commandline legth problem linking a shared library DavePrince Linux - Software 0 07-20-2005 08:19 AM
any links on linking, loading shared libraries, shared objects. etc? ananthbv Programming 0 02-03-2005 07:47 AM
Linking a platform independent shared library rozeboom Programming 3 11-18-2003 02:10 PM


All times are GMT -5. The time now is 05:36 AM.

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