bad reloc address 0x0 in section `.pdata'... trying to compile cython module on Win 8.1 x64

442 views
Skip to first unread message

Evgeny Frolov

unread,
May 6, 2015, 10:26:06 AM5/6/15
to cython...@googlegroups.com
Hi,

I've read almost every post related to problems with cython and openmp but couldn't come up with the solution to my problem.
My current setup:
OS: Windows 8.1 64 bit
Python version: Anaconda Python 2.7.6 64 bit
GCC version: 4.9.2 (was manually upgraded, see below)
Compiling  .pyx files works fine if not used with openmp.

The problem is: I'm trying to compile simple cython module that uses prange from cython.parallel. The setup.py file contents are:

cymodule = 'cython_openmp'
extensions = [
    Extension(cymodule, [cymodule + '.pyx'],
        include_dirs=[numpy.get_include()],
        extra_compile_args=["-fopenmp"],
        extra_link_args=["-fopenmp"])
]
setup(
    ext_modules = cythonize(extensions)
)

The default anaconda environment won't let me to compile this as it's shipped with no-openmp version of MinGW. In order to get openmp support I followed these steps:
1. Downloaded Carl Kleffner (carlkl) mingw static toolchain (https://bitbucket.org/carlkl/mingw-w64-for-python/downloads/mingw64static-2014-11.tar.xz)
2. Unzipped the archive and replaced original Anaconda/MinGW folder with the archive's contents (this gives me 4.9.2 version of GCC instead of original 4.7.0)
3. Generated new libpython27.a file with gendef and dlltool as described here https://groups.google.com/d/msg/winpython/HUJD20S9_yg/JEmKJFrsaAQJ
4. [after I failed to get it working with previous steps] Installed libpython libraries from http://www.lfd.uci.edu/~gohlke/pythonlibs/#libpython

No matter what, running python setup.py build_ext always gives me following errors:

\Anaconda\Scripts\gcc.bat -DMS_WIN64 -shared -s build\temp.win-amd64-2.7\Release\cython_openmp.o build\te
mp.win-amd64-2.7\Release\cython_openmp.def -L\Anaconda\libs -L\Anaconda\PCbuild\amd64 -lpy
thon27 -lmsvcr90 -o build\lib.win-amd64-2.7\cython_openmp.pyd -fopenmp
/Anaconda/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/lib/../lib/dllcrt2
.o:crtdll.c:(.text+0xb): undefined reference to `malloc'
======/ same dllcrt2 path /======
.o:crtdll.c:(.text+0xbd): undefined reference to `_amsg_exit'
======/ same dllcrt2 path /======
.o:crtdll.c:(.text+0x1d3): undefined reference to `free'
======/ same dllcrt2 path /======
.o:crtdll.c:(.text+0x249): undefined reference to `_initterm'
======/ same dllcrt2 path /======
.o:crtdll.c:(.text+0x258): undefined reference to `_amsg_exit'
======/ same dllcrt2 path /======
.o:crtdll.c:(.text+0x270): undefined reference to `_initterm'
/Anaconda/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe:
/Anaconda/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/lib/../lib/dllcrt2.o:
bad reloc address 0x0 in section `.pdata'
collect2.exe: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

I couldn't find anything similar to this on the internet and feel lost here. Any help on this is more than appreciated.


Thanks!
Evgeny

Evgeny Frolov

unread,
May 6, 2015, 12:14:12 PM5/6/15
to cython...@googlegroups.com
I couldn't believe that I missed one important thing: copy \x86_64-w64-mingw32\lib\libmsvcr90.a file to Anaconda/libs folder. After that I was able to compile my cython module.
 
So to answer my own question and for the reference in case somebody looks for this answer later here's the full guide on  how to get it working on Windows x64 with Anaconda Python 2.7 (basically everything was already explained by Carl Kleffner in this thread https://groups.google.com/d/msg/winpython/HUJD20S9_yg/nkce6pWuINEJ, also there were many helpful comments from Sturla Molden):
 
  1. Get current MinGW static toolchain from here

https://bitbucket.org/carlkl/mingw-w64-for-python/downloads

For example, this one mingwpy_amd64_vc90.7z. 

  1. Unpack contents into Anaconda/MinGW folder (replace it's contents).

It maybe a good idea to backup that folder first.

  1. Ensure that msvcr90 is the default crt:
  2. Note that msvcr90 linkage is required for Python 2.6, 2.7, 3.1, 3.2.

    copy contents of the file
    lib\gcc\x86_64-w64-mingw32\<gcc ver>\specs90
    into
    lib\gcc\x86_64-w64-mingw32\<gcc ver>\specs

 

  1. ensure to use correct import file for python27.dll
    • remove or backup an existing Anaconda/libs/libpython27*.a file
    • Copy gendef and dlltool to Anaconda root folder
    • cd to the folder and do

gendef python27.dll      (creates python27.def)

dlltool -D python27.dll -d python27.def -l libpython27.a

    • move libpython27.a to Anaconda/libs

    • remove any msvcrXX.a import files in the Anaconda/libs folder

  1. Ensure correct dependencies
    • remove or backup an existing Anaconda/libs/libmsvcr90.a file
    • copy \x86_64-w64-mingw32\lib\libmsvcr90.a file to Anaconda/libs folder
 
Now I'm trying to get it working in ipython notebook. It seems there are some tricky parts on compilation inside the notebook. Probably I'll post another question in case I won't figure out how to do this.

Thanks,
Evgeny
Reply all
Reply to author
Forward
0 new messages