Guest User

Untitled

a guest
May 20th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #ifndef HELLO_WORLD_CALCULATOR_H
  2. #define HELLO_WORLD_CALCULATOR_H
  3. class Calculator {
  4. public:
  5. double add(double first, double second);
  6. };
  7. #endif
  8.  
  9. #include "Calculator.h"
  10. double Calculator::add(double first, double second) {
  11. return first + second;
  12. }
  13.  
  14. #include <iostream>
  15. #include <tr1/memory>
  16. #include "Calculator.h"
  17.  
  18. using namespace std;
  19.  
  20. double add1(double first, double second){
  21. shared_ptr<Calculator>calculater(new Calculator());
  22. return calculater->add(first, second);
  23. }
  24.  
  25. extern "C"
  26. {
  27. double add(double f, double s){
  28. return add1(f,s);
  29. }
  30. }
  31.  
  32. # coding=utf-8
  33.  
  34. import ctypes
  35. from ctypes import *
  36.  
  37. if __name__ == "__main__":
  38. lib = ctypes.CDLL("./test.so")
  39. lib.add.argstype = [c_double, c_double]
  40. lib.add.restype = c_double
  41. print lib.add(c_double(12), c_double(36))
  42.  
  43. Traceback (most recent call last):
  44. File "test.py", line 9, in <module>
  45. lib = ctypes.CDLL("./test.so")
  46. File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
  47. self._handle = _dlopen(self._name, mode)
  48. OSError: ./test.so: undefined symbol: _ZN10Calculator6devideEdd
Add Comment
Please, Sign In to add comment