[Qt-interest] Create Linux shared library with Qt behind C interface

Jeffrey Brendecke jwbrendecke at icanetix.com
Sat Mar 20 04:36:51 CET 2010


I am looking to create a shared library for use as an extension to a daemon 
that interacts with extensions through a C interface, with the real work done 
by Qt behind this interface without the daemon being aware of this.

Working up to this I have just used a const std::string defined in an unnamed 
namespace that should become exposed to the C-portion as char*. The C++ file 
looks like this:

#include <string>

extern "C" const char* getString();

namespace
{
const std::string someString_( "fooo" );
}

const char* getString()
{
  return someString_.c_str();
}

In the C file: I declared the folling line:

extern char* getString();

... and the C code calls into the C++ code through this function.

My thought was to compile the separate .o files, one with gcc and the other 
with g++ and then link them together into the .so.

In the end, I get no errors when compiling the object files and linking them 
together (even with -Wall), but I get such error messages when trying to load 
the library at runtime:

undefined symbol: __gxx_personality_v0

I think I need to link something in, but am not sure on either what I need to 
link in nor how to do it.

I have checked the following and am still not sure how to actually get this to 
work:
 http://tldp.org/HOWTO/Program-Library-HOWTO/index.html
 The Qt 4.5 Documentation: Creating Shared Libraries
 http://techbase.kde.org/Policies/Binary_Compatibility_Issues_With_C++

Questions:
* Would anyone know of good documentation on this that could help me get 
started in the right direction?

* Are there any additional considerations when trying to use the Qt library, 
for example, QString instead of std::string, beyond the obvious need to 
encode the string data properly?

g++ 4.2.4
Qt 4.5.1 OSS

Thank you very much for any assistance.

Sincerely,

Jeffrey Brendecke

Managing Director
icanetix Software Systems and Consulting GmbH
Untere Hagenstrasse 26
91217 Hersbruck
Germany

Commercial Registry B 25317 Nuremberg, Germany
VAT-ID: DE250213502



More information about the Qt-interest-old mailing list