Undefined character error for base class in C ++ shared library

I compiled the following code as a shared library using g++ -shared ...:

class Foo {
public:
  Foo() {}
  virtual ~Foo() = 0;
  virtual int Bar() = 0;
};

class TestFoo : public Foo {
public:
  int Bar() { return 0; }
};

extern "C" {
  Foo* foo;
  void init() {
    // Runtime error: undefined symbol: _ZN3FooD2Ev
    foo = new TestFoo(); // causes error
  }
  void cleanup() { delete(foo); }
  void bar() { foo->Bar(); }
}

The goal is to expose the functionality of my classes (here at least the minimum toy classes as an example) as a simple API Cwith three functions init, cleanupand bar.

When I try to load a shared library (using dyn.loadin R), I get an error message:

unable to load shared library 'test.so':
test.so: undefined symbol: _ZN3FooD2Ev

So it looks like he cannot find the constructor Foo. What am I doing wrong and how can I fix this?

: , jbar! Foo. : _ZN3FooD2Ev? D FooD ?

+3
3

. , ( ) .

+7

UPDATE: Foo. : _ZN3FooD2Ev? D FooD ?

++ filt.

, ++ filter _ZN3FooD2Ev "Foo:: ~ Foo()".

+13

Regarding your update, "_ZN3FooD2Ev" is "Foo :: ~ Foo ()" crippled .

Check out the demangle program.

+2
source

Source: https://habr.com/ru/post/1712383/


All Articles