[IPython-User] calling C

Christoph Kukulies kuku@physik.rwth-aachen...
Mon Jan 27 03:15:50 CST 2014


I have the following notebook:

%%file functions.c

#include <stdio.h>

void hello(int n);
void

hello(int n)
{
     int i;

     for (i = 0; i < n; i++)
     {
         printf("C says hello world\n");
     }
}

---------------------------------------
!gcc -c -Wall -O2 -Wall -ansi -pedantic -o functions.o functions.c
!gcc -o libfunctions.so -shared functions.o

---------------------------------------
%%file functions.py

import numpy
import ctypes

_libfunctions = numpy.ctypeslib.load_library('libfunctions', '.')

_libfunctions.hello.argtypes = [ctypes.c_int]
_libfunctions.hello.restype  =  ctypes.c_void_p


def hello(n):
     return _libfunctions.hello(int(n))
-----------------------------------------
%%file run_hello_c.py

import functions.py

functions.hello(0)
-----------------------------------------
!python run_hello_c.py
-----------------------------------------

Traceback (most recent call last):
   File "run_hello_c.py", line 2, in <module>
     import functions.py
   File "C:\Users\kuku\Documents\IPython Notebooks\functions.py", line 5, in <module>
     _libfunctions = numpy.ctypeslib.load_library('libfunctions', '.')
   File "C:\Users\kuku\Anaconda\lib\site-packages\numpy\ctypeslib.py", line 131, in load_library
     raise exc
WindowsError: [Error 126] Das angegebene Modul wurde nicht gefunden

-------------------------

This also happens (with a more precise traceback) when you just do

--------------
import functions
--------------
--------------------------------------------------------------------------
WindowsError                               Traceback (most recent call last)
<ipython-input-18-f5ebad54091d>  in<module>()
----> 1  import  functions.py

C:\Users\kuku\Documents\IPython Notebooks\functions.py  in<module>()
       3  import  ctypes
       4  
----> 5  _libfunctions  =  numpy.ctypeslib.load_library('libfunctions',  '.')
       6  
       7  _libfunctions.hello.argtypes=  [ctypes.c_int]

C:\Users\kuku\Anaconda\lib\site-packages\numpy\ctypeslib.pyc  inload_library(libname, loader_path)
     129              except  OSError,  e:
     130                  exc=  e
--> 131          raise  exc
     132  
     133      ctypes_load_library = deprecate(load_library, 'ctypes_load_library',

WindowsError: [Error 126] Das angegebene Modul wurde nicht gefunden


Any clues?

--
Christoph




More information about the IPython-User mailing list