[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: C++/Python .so Problem ergänzung



Hallo,

Volker Weißmann <volker.weissmann@gmx.de> writes:

> Am 05.07.2014 18:46, schrieb Volker Weißmann:
>> Hallo, ich habe mal den Compelier-Befehlt geändert: g++ -shared
>> -Wall -Wextra -pedantic src/RoboTest.cpp -o RASAPI.so Jetzt
>> funktioniert das Python Skript: from ctypes import CDLL aou =
>> CDLL("/home/volker/Dokumente/RoboterAG/RASAPI/RASAPI.so") Wenn ich
>> allerdings am Ende noch ein aou.test() daran hänge erhalte ich
>> folgende ausgabe: Traceback (most recent call last): File
>> "python.py", line 3, in <module> aou.test() File
>> "/usr/lib/python2.7/ctypes/__init__.py", line 378, in __getattr__ 
>> func = self.__getitem__(name) File
>> "/usr/lib/python2.7/ctypes/__init__.py", line 383, in __getitem__ 
>> func = self._FuncPtr((name_or_ordinal, self)) AttributeError:
>> absoluerPfad/RASAPI.so: undefined symbol: test
> Wenn ich den Code in
> #include <stdio.h>
> extern "C" void test()
> {
> 	printf("test");
> }
> ändere, funktioniert aou.test(). Aber ich will ja auch Klassen und
> Exceptions haben, die es in C nicht gibt.
ich schrub ja schon, dass das name mangling dort einen Strich durch die
Rechnung macht. Der einzige gescheite Weg, der mir ad hoc einfaellt, ist
extern "C" {} zu verwenden und das dann in Python-Klassen zu wrappen:

extern "C" {
    foo* foo_new(){ return new foo(); }
    void foo_bar( foo *_foo ){ _foo->bar(); }
}

VG
hmw

-- 
biff4emacsen - A biff-like tool for (X)Emacs
http://www.c0t0d0s0.de/biff4emacsen/biff4emacsen.html
Flood - Your friendly network packet generator
http://www.c0t0d0s0.de/flood/flood.html


Reply to: