2

I am doing one simple program where the C++ function is called from a Python. I am running this code in Raspberry Pi having Raspbian OS. Here I am using ctypes to call the C++ from python. Here is my code test.cpp:

#ifdef __cplusplus
extern "C"
#endif
class cppmax
{
int num1;
int num2;
int max(num1,num2) 
{
  // local variable declaration
  int result;

  if (num1 > num2)
    result = num1;
  else
    result = num2;

  return result; 
}
};

And my another python code is test.py:

from ctypes import *

cmax = cdll.LoadLibrary('./test.dll').max
cmax.argtypes = [c_int, c_int] # arguments types
cmax.restype = c_int           # return type, or None if void
a = int(raw_input("Enter 1st no"))
b = int(raw_input("Enter 2nd no"))
print "Your answer is :", cmax(a,b)

These code are working on Ubuntu, but in Raspberry Pi it is giving error as:

Traceback (most recent call last)
  File "test.py", line 3, in <module>
    cmax=cdll.LoadLibrary('/home/pi/calling+cpp/test.dll').max
  File "/usr/lib/python2.7/ctypes/_init_.py", line 365, in _init_
    self._handle = _dlopen(self._name, mode)
OSError: /home/pi/calling_cpp/test.dll: cannot open shared object file: No such file or directory

for the compiling C++ I have used the command as:

g++ -Wall test.cpp -shared -o test.dll

I have tried as posted in question : cannot open shared object file: No such file or directory, but it didn't work

Community
  • 1
  • 1
lkkkk
  • 1,999
  • 4
  • 23
  • 29
  • I'm not sure this will work, but have you tried adding your project folder to the library path, and loading `'test.dll'` instead of via relative path? I think that's the canonical way to do it. – Alex Z May 23 '14 at 12:17
  • I tried by using command : `export LD_LIBRARY_PATH=/home/pi/calling_cpp:$LD_LIBRARY_PATH`, but it didn't work. – lkkkk May 23 '14 at 17:01
  • did you have any progress? I have the same issue and cannot resolve it. – amazpyel Dec 14 '15 at 11:25

1 Answers1

0

See : "On Linux, find_library() tries to run external programs(/sbin/ldconfig, gcc, and objdump) to find the library file. Itreturns the filename of the library file", Try add /usr/local/lib to /etc/ld.so.conf new line,then sudo ldconfig Link: http://blog.csdn.net/wolfzhaoshuai/article/details/46520371 (in Chinese)

Follow this, I solved similar problem.

miket
  • 167
  • 1
  • 9