Hi,
I used SCons to create a shared library (dll) from a c++ file (hello.cpp) below. Then I used Python and it ctypes library to load in the dll and call its functions. I can load the dll and call the main function, but nothing else. I cannot call the other prototyped functions in the cpp file or get values of constants. I am pretty sure they are in the dll (any tool to find them?). The Python script is below. How can access the functions other than main and other constants in the dll created from the cpp file?
Thanks!
-Vic
from ctypes import *
c = cdll.LoadLibrary("hello.dll")
print c.main(5,4)
print c.rr
print c.add(5,6)
print c.minus(5,1)
Error Message:
>>>
9
Traceback (most recent call last):
File "C:\Documents and Settings\Your Name\Desktop\compile_attempts\testscons.py", line 6, in <module>
print c.rr
File "C:\Python25\lib\ctypes\__init__.py", line 361, in __getattr__
func = self.__getitem__(name)
File "C:\Python25\lib\ctypes\__init__.py", line 366, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'rr' not found
hello.cpp
#include <iostream>
using namespace std;
int add(int r, int q);
int minus(int r, int q);
int times(int r, int q);
int divide(int r, int q);
int main(int r, int q)
{
cout << "Hello, world!\n";
r = add(q,r);
return r;
}
int add(int r, int q)
{
cout << "Hello, world!\n";
return r+q;
}
int minus(int r, int q)
{
cout << "Hello, world!\n";
return r-q;
}
int times(int r, int q)
{
cout << "Hello, world!\n";
return r*q;
}
int divide(int r, int q)
{
cout << "Hello, world!\n";
return r/q;
}