ImportError: DLL load failed: specified procedure could not be found.

1,035 views
Skip to first unread message

Lionel

unread,
Apr 13, 2010, 5:12:08 PM4/13/10
to cython-users
Hello,

I'm quite new to Cython.
I ran the examples succesfully, but I then tried to get a little
further.
Here is my problem.

I created a DLL in C which creates and opens a window with the SDL,
and sets up an OpenGL 3.2 context for me.
I stored all the useful datas in a struct.

I have 2 simple functions: createCtx(), deleteCtx().

As I code on Windows XP, I specified the dllexport flag before each
symbol. Anyway, my DLL compiles good, and I can use it in a C
application.

I then followed the example available on docs.cython.org:
I created a .pxd file, with the usual "cdef extern from myLib.h:" and
rewrote my declarations as such:

cdef extern from "GLSDLCTX.h":
ctypedef struct GLSDLHANDLERS:
pass

ctypedef struct GLSDLCTX:
pass

etc...

I then wrote the actual wrapper around my class as such:

cimport python_exc
cimport cGLSDLCTX

cdef class GlCtx:

cdef cGLSDLCTX.GLSDLCTX * _ctx

def __cinit__(self):
self._ctx = cGLSDLCTX.createCtx()
if self._ctx is NULL:
python_exc.PyErr_NoMemory()

def __dealloc__(self):
if self._ctx is not NULL:
cGLSDLCTX.deleteCtx(self._ctx)

I created a build.py carefully, and it all compiles cleanly, without
any error. I get a nice myModule.pyd

But here is my problem:
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit
(Intel)] on win32
>>> import myModule
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: specified procedure could not be found.
>>>

I really tried everything. Tweaking the sys.path, copying every other
usefull DLL in the local directory etc... I don't understand what I
missed.

Python -v didn't really help to spot the actual DLL that causes
trouble. I'm really helpless right now, I can just hope that any of
you did get the same error at some point and found a workaround.

Thanks,

Lionel

Lisandro Dalcin

unread,
Apr 13, 2010, 9:00:56 PM4/13/10
to cython-users

http://www.dependencywalker.com/

PS: The whole business of DLL's, SxS assemblies, manifests, and all
that nonsensical crap is something I still to not fully understand, so
try to use depends.exe utility to try to figure out what's wrong with
your DLL dependencies.

--
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169

Lionel Data

unread,
Apr 14, 2010, 5:06:27 AM4/14/10
to cython...@googlegroups.com
That really didn't help.
I could spot 2 DLL (wer.dll / ieshims.dll) that were causing errors, but they do even if I run python.exe -c 'print hello' and it works just fine.

I recompiled every library I am using (SDL and my own one) and double checked that I use the same runtime dll's and stuff, and I still have the problem... wtf ! :(

2010/4/14 Lisandro Dalcin <dal...@gmail.com>


--
To unsubscribe, reply using "remove me" as the subject.

Lionel Data

unread,
Apr 14, 2010, 5:12:11 AM4/14/10
to cython...@googlegroups.com
Is there even a way to have Python be more verbose about the DLL that it failed to load ? Some kind of secret mega verbose mode ?
When I run Python -vvv I get this stuff:

>>> import glsdlctx
# trying glsdlctx.pyd

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed: specified procedure could not be found.
>>>

Why does it argue with a procedure ? What procedure ? :/



2010/4/14 Lionel Data <lione...@gmail.com>

Lionel Data

unread,
Apr 14, 2010, 5:48:00 AM4/14/10
to cython...@googlegroups.com
Ok, sorry for the mega multi post, but here are some procisions.

After commenting / recompiling my Cython code, it turns out my import fails as soon as I call a function from my C dll.

I tried to comment code in my C dll too, and it still fails even when my C functions are empty, so the problem is really the glue between the C and the Cython.

Here is my code in its entirety. I followed the tutorials to the letter, so I really don't know what to do now...I triple checked the symbols names in my dll and they are fine: no c++ mangling etc... What could I have missed ?


cimport python_exc
cimport cGLSDLCTX

cdef    class GlCtx:

    cdef cGLSDLCTX.GLSDLCTX * _ctx
 
    def __cinit__(self):
        print 'alloc'
        self._ctx = cGLSDLCTX.createCtx() # the import will success if I comment this.

        if self._ctx is NULL:
            python_exc.PyErr_NoMemory()
   
    def __dealloc__(self):
        if self._ctx is not NULL:
            print 'dealloc'
        #            cGLSDLCTX.deleteCtx(self._ctx)


If anyone has an idea, please let me know. Thanks.

Lionel


2010/4/14 Lionel Data <lione...@gmail.com>

Lisandro Dalcin

unread,
Apr 14, 2010, 10:12:54 AM4/14/10
to cython...@googlegroups.com
On 14 April 2010 06:12, Lionel Data <lione...@gmail.com> wrote:
> Is there even a way to have Python be more verbose about the DLL that it
> failed to load ? Some kind of secret mega verbose mode ?
> When I run Python -vvv I get this stuff:
>
>>>> import glsdlctx
> # trying glsdlctx.pyd
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ImportError: DLL load failed: specified procedure could not be found.
>>>>
>
> Why does it argue with a procedure ? What procedure ? :/
>

Perhaps that error message does not came for Python itself, but from a
failing (likely because of missing dependency) LoadLibrary() call when
Python imports your module?

Lisandro Dalcin

unread,
Apr 14, 2010, 10:18:06 AM4/14/10
to cython...@googlegroups.com
On 14 April 2010 06:48, Lionel Data <lione...@gmail.com> wrote:
>
> If anyone has an idea, please let me know. Thanks.
>

1) Missing DLL on your system (C:Win\Sys32 of SxS assembly).
2) Missing library in your setup.py
3) Mangling (perhaps because of calling conventions) issue.

That's the things I can think of with the info at hand.

Lionel Data

unread,
Apr 15, 2010, 4:15:08 AM4/15/10
to cython...@googlegroups.com
Ok I solved the problem thanks to Linux which offers a much nicer debug and tells exactly what symbol was missing. Turns out some symbols could not be found in shared libraries and I had to tweak with the LD_LIBRARY_PATH variable to have it work.

I think I will fix this using the -rpath option for the linker on Linux and ... I don't know yet on Windows.

Thanks for your support.

Lionel

2010/4/14 Lisandro Dalcin <dal...@gmail.com>

Lisandro Dalcin

unread,
Apr 15, 2010, 10:05:08 AM4/15/10
to cython...@googlegroups.com
On 15 April 2010 05:15, Lionel Data <lione...@gmail.com> wrote:
> Ok I solved the problem thanks to Linux which offers a much nicer debug and
> tells exactly what symbol was missing. Turns out some symbols could not be
> found in shared libraries and I had to tweak with the LD_LIBRARY_PATH
> variable to have it work.
>
> I think I will fix this using the -rpath option for the linker on Linux and
> ... I don't know yet on Windows.
>

Y think you have to pass the full -LC:\path\to\libdir to the import
library at build time, and make sure the actual DLL is in
C:\Win32\Sys32 or other standard locations... Sorry, I cannot help
further, I know almost nothing about Windows.

gordianknot

unread,
Sep 15, 2013, 2:04:10 AM9/15/13
to cython...@googlegroups.com

I solved my problem by using msvc build instead of g++ build.
All I have to do is download and install windows sdk7 and the following build step


:: 1/ C:\Windows\System32\cmd.exe /E:ON /V:ON /T:0E /K [your batch script]

:: ex:C:\Windows\System32\cmd.exe /E:ON /V:ON /T:0E /K make.bat


:::::::::::::::::::::::::::::::::::::::::::
:: in make.bat file:
::::::::::::::::::::::::::::::::::::::::::

:: 2/ call vcvars32.bat

::

:: 3/ call setenv /x86 /Release

:: you could find setenv.cmd under windows sdk7

:: ex: D:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\SetEnv

::

:: 4/ set DISTUTILLS_USE_SDK = 1

::

:: 5/ setup your program
::
:: 6/ python setup.py build_ext --inplace --compiler=msvc





Lionel於 2010年4月14日星期三UTC+8上午5時12分08秒寫道:

Sturla Molden

unread,
Sep 16, 2013, 12:36:09 PM9/16/13
to cython...@googlegroups.com
Be careful which SDK version you use. It must be the same used to build Python. This has to do with linking against the same C runtime DLL as Python. Every version of the MSVC compiler links against a new version of the C runtime, and you cannot control with which to link.

Thus for Python 2.7 we must use Windows SDK for .NET 3.5. It is also known under other names, such as MSVC 9 or Visual Studio 2008. 

Do not use any other version of MSVC for Python 2.7! Do not use the Windows 7 SDK for Python 2.7! It will appear to work for a while (i.e. not segfault).  But the heap will gradually be corrupted. And as errno is a global variable in the C runtime DLL, exceptions will not work correctly.

(For other Python versions than 2.7 I am not sure which one to use. I do not keep track of Python 3.x ...)

The Mingw compiler on the other hand allows us to choose the C runtime we want.

As MSVC 9 is an old compiler, I prefer to use GCC 2.7 (e.g. from TDM-GCC) on Windows and link with -lmsvcr90. Note that the import library libmsvcr90.a is not shipped with 64-bit Python. You must build it yourself or get it from somewhere else (e.g. Enthought). Finally, to get this to build, we must edit the Mingw32 compiler class in distutils and get rid of the -mno-cygwin flag. It prevents extensions to build with recent GCC versions (2.6 and later, AFAIK). It is a known bug in distutils but it will not be fixed in Python 2.7 so you must do it yourself.

Sturla


Sendt fra min iPad
--
 
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Sturla Molden

unread,
Sep 16, 2013, 12:43:35 PM9/16/13
to cython...@googlegroups.com
Oh yes, and if you want to cuss out at someone for making C runtime DLL hell, the appropriate address would be in Redmond, Washington.

Sturla

Sendt fra min iPad
Reply all
Reply to author
Forward
0 new messages