Problems in connecting C++ and python with cppyy

Hi, When I use cppyy to connect the C++ with the python, I got a failure. Following this page, https://pypy.readthedocs.org/en/improve-docs/cppyy.html Define a new class $ cat MyClass.h class MyClass { public: MyClass(int i = -99) : m_myint(i) {} int GetMyInt() { return m_myint; } void SetMyInt(int i) { m_myint = i; } public: int m_myint; }; then compile it. $ genreflex MyClass.h $ g++ -fPIC -rdynamic -O2 -shared -I$REFLEXHOME/include MyClass_rflx.cpp -o libMyClassDict.so -L$REFLEXHOME/lib -lReflex $ ls libMyClassDict.so MyClass.h MyClass_rflx.cpp BUT, when I tried to load it in pypy-c, error occurred. $ pypy-c
import cppyy cppyy.load_reflection_info("libMyClassDict.so") Traceback (most recent call last): File "<stdin>", line 1, in <module> RuntimeError: libMyClassDict.so: cannot open shared object file: No such file or directory
Help me please? Thanks.

Hi, On Fri, May 24, 2013 at 8:45 AM, Xia Xin <xiaxinx@gmail.com> wrote:
cppyy.load_reflection_info("libMyClassDict.so")
I believe that you need to say "./libMyClassDict.so". Otherwise it's searching for the .so in the system's standard places, which do not include ".". A bientôt, Armin.

Hi,
On Fri, May 24, 2013 at 8:45 AM, Xia Xin <xiaxinx@gmail.com> wrote: I believe that you need to say "./libMyClassDict.so". Otherwise it's searching for the .so in the system's standard places, which do not include ".".
yes, or add '.' to LD_LIBRARY_PATH. The call is basically just a dlopen: internally, it uses libffi.CDLL(). Note that if the automatic class loader is used, the same rules apply, as .rootmap files available through LD_LIBRARY_PATH are used for auto-loading. I've clarified this in the documentation. Thanks, Wim -- WLavrijsen@lbl.gov -- +1 (510) 486 6411 -- www.lavrijsen.net

Hi, Wim I tried, but when I use the automatic class loader, the problem still exists. HERE is the error. 1. $ echo $LD_LIBRARY_PATH /home/GeV/work/hello/v1/src:/opt/root/lib/root $ ls /home/GeV/work/hello/v1/src libMyClassDict.rootmap libMyClassDict.so MyClass.h MyClass_rflx.cpp
import cppyy myinst = cppyy.gbl.MyClass(42) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: <class '__main__.::'> object has no attribute 'MyClass' (details: '<class '__main__.::'>' has no attribute 'MyClass')
2. TRY explicit load statements, Just as that Armin told me, It's OK, works perfectly $ echo $LD_LIBRARY_PATH /opt/root/lib/root
import cppyy cppyy.load_reflection_info("./libMyClassDict.so") myinst = cppyy.gbl.MyClass(42) 42
3. Use LD_LIBRARY_PATH to clarify the path to libMyClassDict.so, still error $ echo $LD_LIBRARY_PATH /home/GeV/work/hello/v1/src:/opt/root/lib/root
import cppyy cppyy.load_reflection_info("libMyClassDict.so") Traceback (most recent call last): File "<stdin>", line 1, in <module> RuntimeError: libMyClassDict.so: cannot open shared object file: No such file or directory
I don't understand why the LD_LIBRARY_PATH did not work well on my PC. Waiting for your reply. Thanks! Best wishes, Xia Xin 2013/5/25 <wlavrijsen@lbl.gov>:
Hi,
On Fri, May 24, 2013 at 8:45 AM, Xia Xin <xiaxinx@gmail.com> wrote: I believe that you need to say "./libMyClassDict.so". Otherwise it's searching for the .so in the system's standard places, which do not include ".".
yes, or add '.' to LD_LIBRARY_PATH. The call is basically just a dlopen: internally, it uses libffi.CDLL().
Note that if the automatic class loader is used, the same rules apply, as .rootmap files available through LD_LIBRARY_PATH are used for auto-loading.
I've clarified this in the documentation.
Thanks, Wim -- WLavrijsen@lbl.gov -- +1 (510) 486 6411 -- www.lavrijsen.net

Hi,
1.
$ echo $LD_LIBRARY_PATH /home/GeV/work/hello/v1/src:/opt/root/lib/root
$ ls /home/GeV/work/hello/v1/src libMyClassDict.rootmap libMyClassDict.so MyClass.h MyClass_rflx.cpp
import cppyy myinst = cppyy.gbl.MyClass(42) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: <class '__main__.::'> object has no attribute 'MyClass' (details: '<class '__main__.::'>' has no attribute 'MyClass')
2. TRY explicit load statements, Just as that Armin told me, It's OK, works perfectly
$ echo $LD_LIBRARY_PATH /opt/root/lib/root
import cppyy cppyy.load_reflection_info("./libMyClassDict.so") myinst = cppyy.gbl.MyClass(42) 42
3. Use LD_LIBRARY_PATH to clarify the path to libMyClassDict.so, still error
$ echo $LD_LIBRARY_PATH /home/GeV/work/hello/v1/src:/opt/root/lib/root
import cppyy cppyy.load_reflection_info("libMyClassDict.so") Traceback (most recent call last): File "<stdin>", line 1, in <module> RuntimeError: libMyClassDict.so: cannot open shared object file: No such file or directory
I don't understand why the LD_LIBRARY_PATH did not work well on my PC.
neither do I, unless /home/GeV/work/hello/v1/src is not the current work directory and you have two libMyClassDict.so. What does: $ ldd /home/GeV/work/hello/v1/src/libMyClassDict.so give? Any libraries to be linked not found? Best regards, Wim -- WLavrijsen@lbl.gov -- +1 (510) 486 6411 -- www.lavrijsen.net

Hi, I am sure /home/GeV/work/hello/v1/src is the current and only work directory. $ ldd libMyClassDict.so linux-vdso.so.1 => (0x00007fff9e598000) libReflex.so.0 => /opt/root/lib/root/libReflex.so.0 (0x00007f7f2e4ec000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f7f2e1d0000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7f2dfb9000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7f2dbfa000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7f2d9f6000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7f2d6f9000) /lib64/ld-linux-x86-64.so.2 (0x00007f7f2e98e000) All needed libraries exist. Errors occur only when I try to use automatic class loader. Best regards, Xia Xin 2013/5/25 <wlavrijsen@lbl.gov>:
Hi,
1.
$ echo $LD_LIBRARY_PATH /home/GeV/work/hello/v1/src:/opt/root/lib/root
$ ls /home/GeV/work/hello/v1/src libMyClassDict.rootmap libMyClassDict.so MyClass.h MyClass_rflx.cpp
import cppyy myinst = cppyy.gbl.MyClass(42)
Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: <class '__main__.::'> object has no attribute 'MyClass' (details: '<class '__main__.::'>' has no attribute 'MyClass')
2. TRY explicit load statements, Just as that Armin told me, It's OK, works perfectly
$ echo $LD_LIBRARY_PATH /opt/root/lib/root
import cppyy cppyy.load_reflection_info("./libMyClassDict.so") myinst = cppyy.gbl.MyClass(42)
42
3. Use LD_LIBRARY_PATH to clarify the path to libMyClassDict.so, still error
$ echo $LD_LIBRARY_PATH /home/GeV/work/hello/v1/src:/opt/root/lib/root
import cppyy cppyy.load_reflection_info("libMyClassDict.so")
Traceback (most recent call last): File "<stdin>", line 1, in <module> RuntimeError: libMyClassDict.so: cannot open shared object file: No such file or directory
I don't understand why the LD_LIBRARY_PATH did not work well on my PC.
neither do I, unless /home/GeV/work/hello/v1/src is not the current work directory and you have two libMyClassDict.so.
What does:
$ ldd /home/GeV/work/hello/v1/src/libMyClassDict.so
give? Any libraries to be linked not found?
Best regards,
Wim -- WLavrijsen@lbl.gov -- +1 (510) 486 6411 -- www.lavrijsen.net

Hi,
All needed libraries exist. Errors occur only when I try to use automatic class loader.
puzzling ... Only thing I can think of is to use LD_DEBUG=files (or with LD_DEBUG=symbols) and see whether either gives an indication as to what is wrong (a library or directory not being considered for loading, or a symbol missing, or ... ). Best regards, Wim -- WLavrijsen@lbl.gov -- +1 (510) 486 6411 -- www.lavrijsen.net

Hi, Sorry, I did not find any mistakes except that AttributeError. So I think maybe there are some problems in my OS. Thanks for your help. if you like, I can also give you an acess to my PC(Newly installed, no secret. :D). Best regards, Xia Xin 2013/5/25 <wlavrijsen@lbl.gov>:
Hi,
All needed libraries exist. Errors occur only when I try to use automatic class loader.
puzzling ... Only thing I can think of is to use LD_DEBUG=files (or with LD_DEBUG=symbols) and see whether either gives an indication as to what is wrong (a library or directory not being considered for loading, or a symbol missing, or ... ).
Best regards, Wim -- WLavrijsen@lbl.gov -- +1 (510) 486 6411 -- www.lavrijsen.net

Hi,
Sorry, I did not find any mistakes except that AttributeError. So I think maybe there are some problems in my OS.
there may still be another problem lurking around that the AttributeError is hiding (and which I'd consider a bug :} ). Could you try the various cases using ctypes.CDLL(), either with CPython or PyPy?
import ctypes ctypes.CDLL('libMyClassDict.so')
If there's an issue with the error reporting, then this may show it. Best regards, Wim -- WLavrijsen@lbl.gov -- +1 (510) 486 6411 -- www.lavrijsen.net

Hi, This is the result. It shows that the pypy-c does not search the LD_LIBRARY_PATH env.
import ctypes ctypes.CDLL('libMyClassDict.so') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/pypy/lib-python/2.7/ctypes/__init__.py", line 367, in __init__ self._handle = _ffi.CDLL(name, mode) OSError: libMyClassDict.so: libMyClassDict.so: cannot open shared object file: No such file or directory ctypes.CDLL('./libMyClassDict.so') <CDLL './libMyClassDict.so', handle <_ffi.CDLL object at 0x000000000493aaa0> at 4895da8>
maybe I make a mistake in compiling the pypy-c? I did that like this. $ hg clone https://bitbucket.org/pypy/pypy $ cd pypy $ hg up reflex-support $ pypy ../../rpython/bin/rpython --Ojit targetpypystandalone --withmod-cppyy Thank you! Best regards, Xia Xin 2013/5/26 <wlavrijsen@lbl.gov>:
Hi,
Sorry, I did not find any mistakes except that AttributeError. So I think maybe there are some problems in my OS.
there may still be another problem lurking around that the AttributeError is hiding (and which I'd consider a bug :} ).
Could you try the various cases using ctypes.CDLL(), either with CPython or PyPy?
import ctypes ctypes.CDLL('libMyClassDict.so')
If there's an issue with the error reporting, then this may show it.
Best regards, Wim -- WLavrijsen@lbl.gov -- +1 (510) 486 6411 -- www.lavrijsen.net

Hi, I think I find the problem. The linux distro I am using is Ubuntu. In the distro, the default library search path is not controlled by LD_LIBRARY_PATH, but /etc/ld.so.conf file! Mad. So, I can load the librarys in /usr/lib with just a name, but have to give a path to the library in my home. Apologize for disturbing you, Thank you all! Best regards, Xia Xin 2013/5/26 Xia Xin <xiaxinx@gmail.com>:
Hi,
This is the result. It shows that the pypy-c does not search the LD_LIBRARY_PATH env.
import ctypes ctypes.CDLL('libMyClassDict.so') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/pypy/lib-python/2.7/ctypes/__init__.py", line 367, in __init__ self._handle = _ffi.CDLL(name, mode) OSError: libMyClassDict.so: libMyClassDict.so: cannot open shared object file: No such file or directory ctypes.CDLL('./libMyClassDict.so') <CDLL './libMyClassDict.so', handle <_ffi.CDLL object at 0x000000000493aaa0> at 4895da8>
maybe I make a mistake in compiling the pypy-c? I did that like this.
$ hg clone https://bitbucket.org/pypy/pypy $ cd pypy $ hg up reflex-support $ pypy ../../rpython/bin/rpython --Ojit targetpypystandalone --withmod-cppyy
Thank you!
Best regards, Xia Xin
2013/5/26 <wlavrijsen@lbl.gov>:
Hi,
Sorry, I did not find any mistakes except that AttributeError. So I think maybe there are some problems in my OS.
there may still be another problem lurking around that the AttributeError is hiding (and which I'd consider a bug :} ).
Could you try the various cases using ctypes.CDLL(), either with CPython or PyPy?
import ctypes ctypes.CDLL('libMyClassDict.so')
If there's an issue with the error reporting, then this may show it.
Best regards, Wim -- WLavrijsen@lbl.gov -- +1 (510) 486 6411 -- www.lavrijsen.net

Hi Xia, First note that cppyy is included in the standard PyPy 2.0.x releases, so you don't need to translate on the 'reflex-support' branch any more. This branch is now giving you an older version actually. On Mon, May 27, 2013 at 8:20 AM, Xia Xin <xiaxinx@gmail.com> wrote:
The linux distro I am using is Ubuntu. In the distro, the default library search path is not controlled by LD_LIBRARY_PATH, but /etc/ld.so.conf file! Mad.
Are you sure? That's strange. Normally that's controlled by both. For me on Ubuntu 12.04 the LD_LIBRARY_PATH variable is correctly handled (see http://bpaste.net/show/102180/ ). A bientôt, Armin.

Hi, Armin Thanks for your reminding. My pypy is now in 2.0.0 beta2 version. I'll recompile it. I'm using Linux Mint 14, which is based on the Ubuntu 12.10. On this distro, Only /etc/ld.so.conf can be used. I tested many times. $ cat /etc/ld.so.conf include /etc/ld.so.conf.d/*.conf /home/GeV/work/hello/v1/src $ sudo ldconfig
ctypes.CDLL('libMyClassDict.so') <CDLL 'libMyClassDict.so', handle <_ffi.CDLL object at 0x00007fcefaaf3c20> at 7fcefaeac2f8>
I do not know why. Maybe Mint has disabled the LD_LIBRARY_PATH for some reasons or a bug... Thanks for your help. Best regards, Xia Xin 2013/5/27 Armin Rigo <arigo@tunes.org>:
Hi Xia,
First note that cppyy is included in the standard PyPy 2.0.x releases, so you don't need to translate on the 'reflex-support' branch any more. This branch is now giving you an older version actually.
On Mon, May 27, 2013 at 8:20 AM, Xia Xin <xiaxinx@gmail.com> wrote:
The linux distro I am using is Ubuntu. In the distro, the default library search path is not controlled by LD_LIBRARY_PATH, but /etc/ld.so.conf file! Mad.
Are you sure? That's strange. Normally that's controlled by both. For me on Ubuntu 12.04 the LD_LIBRARY_PATH variable is correctly handled (see http://bpaste.net/show/102180/ ).
A bientôt,
Armin.
participants (3)
-
Armin Rigo
-
wlavrijsen@lbl.gov
-
Xia Xin