dlopen error with newly introduced (but still unused) c++ class

John Ralls jralls at ceridwen.us
Sat Jan 30 11:33:56 EST 2016


> On Jan 30, 2016, at 6:04 AM, Geert Janssens <geert.gnucash at kobaltwit.be> wrote:
> 
> Hi,
> 
> I'm adding c++ code to the csv-importer. Various classes have been defined so far, 
> though they aren't really in use yet. They are compiled and linked into the csv-import 
> shared lib.
> 
> When running gnucash in this setup, I get this warning:
> 
> WARN <gnc.module> Failed to dlopen() 
> '/home/janssege/Lokaal/installs/gnucash/master/lib/gnucash/libgncmo
> 
> And the csv import functionality is skipped.
> 
> I understand this has to do with dlopen not understanding c++ name mangling, but don't 
> know how to avoid it.
> 
> The classes I have introduced so far don't need to be exposed to the rest of gnucash. They 
> are intended for internal use in the csv importer only.
> 
> How can I shield them from dlopen, or otherwise put, mark them as not exportable ?

I'm a bit puzzled about how exactly the C++ bits are integrated with the rest of the importer, but I think your problem is that you're including C-linkage headers into C++ without declaring them as such. For example in gnc-csv-imp-trans.hpp, you have

#include "config.h"
#include "Account.h"
#include "Transaction.h"
#include <vector>
#include <memory>

it needs to be

extern "C"
{
#include "config.h"
#include "Account.h"
#include "Transaction.h"
}
#include <vector>
#include <memory>

to tell the compiler to use unmangled names for the symbols from those headers. That lack of mangling is called C linkage. You need to do that in both headers and implementations. If a header will be included in a C file, wrap the 'extern "C" {' and closing } with #ifdef __cplusplus … #endif so that the C compiler doesn't see it.

Any C++ functions called from C need to also have C linkage, and obviously must be free functions, not class members. Only the declarations need be wrapped in extern "C" {…}. The definitions shouldn't be and can be as C++-y as you want. You can look at qof/gnc-numeric to see an example.

Regards,
John Ralls




More information about the gnucash-devel mailing list