From: Mike E. <eas...@gm...> - 2008-01-09 15:55:46
|
I have been successful in creating a module using SWIG by following the tutorial posted on the website. However, when I try to import the module into the interpreter, I get the error: >>> import calccrc Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: dynamic module does not define init function (initcalccrc) Am I creating the interface file incorrectly? Is the unsigned char* not being handled correctly by SWiG? Do I need to make a complete program out of the C Source File, or make a full class out of it? Thanks for any help that can be given. =-=-=-=-=-=-=-=-=-=- Details -=-=-=-=-=-=-=-=-=-=-=-= Module Name: calccrc SWiG Interface File: calccrc.i /* calccrc.i */ %module calccrc %{ extern unsigned short calc_crc(int x, unsigned char *outbound_message); %} extern unsigned short calc_crc(int n, unsigned char *outbound_message); C Source Code File: calccrc.c unsigned short calc_crc(int n,unsigned char *outbound_message) { unsigned char carry_flag; unsigned short crc=0xFFFF; int i, j; for (i = 0; i < n; i++) { crc = crc ^ outbound_message[i]; for (j = 0; j < 8; j++) { carry_flag = crc & 0x01; crc = crc >> 1; if (carry_flag == 1) { crc = crc ^ 0xA001; } } } return crc; } -- Michael Easter "In a world without fences and walls, there would be no need for Windows and Gates" |