function/symbol 'testlib' not found in library 'conv.dll': error 0x7f

213 views
Skip to first unread message

Paolo Galizzi

unread,
Oct 26, 2017, 10:05:45 AM10/26/17
to python-cffi
I'm trying to run a python code tested on OSX on Windows 10, but I'm not able to load or use the dll imported with cffi.
I minimize the problem, creating this file conv.c :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int testlib(int a){
 
return a;
}



and compiling it using Visual Studio Express 2012 for Windows Desktop.

Then I made this run.py file:

from cffi import FFI
ffi
= FFI()
ffi
.cdef("""
    int testlib(int a);
"""
)


t
= ffi.dlopen('conv')
t
.testlib(2)

If I call the run.py using python 2.7.14 or 3.6.3 I got this error:

AttributeError: function/symbol 'testlib' not found in library 'conv.dll': error 0x7f

I need to export variable into my conv.c ? Or something else? On OSX works without any problem.

Thanks.

Armin Rigo

unread,
Oct 27, 2017, 6:20:27 AM10/27/17
to pytho...@googlegroups.com
Hi,

On 26 October 2017 at 16:05, Paolo Galizzi <paolof....@gmail.com> wrote:
> int testlib(int a){
> return a;
> }

On Windows, this is not enough to make the function exported from the
DLL. In other words, whereas on POSIX systems all non-static
functions are exported by shared libraries (by default), it does not
work like this on Windows. You need either to use a .def file, or say
in the C source:

__declspec(dllexport) int testlib(int a) {
return a;
}

You can also look up cffi/_embedding.h, which defines the macro
"CFFI_DLLEXPORT"; I know you're not doing embedding (and the problem
is completely independent of CFFI) but you might want to write
something similar to these seven lines of code in your own C library,
for portability.


A bientôt,

Armin.
Reply all
Reply to author
Forward
0 new messages