简体   繁体   中英

Error in opening shared object file in python ( OSError: cannot open shared object file: No such file or directory)

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM