Python 3.4 Winrandom compiling error - python

I am trying to compile winrandom and got the followint error.
Please help - what could be the reason?
c:\MinGW\bin\gcc.exe -shared -s build\temp.win32-3.4\Release\src\winrandom.o bui
ld\temp.win32-3.4\Release\src\winrandom.def -LC:\Python34\libs -LC:\Python34\PCb
uild -lCrypt32 -lpython34 -lmsvcr100 -o build\lib.win32-3.4\winrandom.pyd
Cannot export PyInit_winrandom: symbol not defined
build\temp.win32-3.4\Release\src\winrandom.o:winrandom.c:(.text+0x437): undefine
d reference to `Py_InitModule'
collect2.exe: error: ld returned 1 exit status
error: command 'c:\\MinGW\\bin\\gcc.exe' failed with exit status 1

Py_InitModule is no longer used in Python 3.X, the package you downloaded is probably for Python 2.X. That is where you issue lies. Try finding a version that is meant for Python 3.X

Related

python script converted to C code via Cython is throwing this error upon execution: undefined symbol: PyObject_SelfIter

I converted a Python script to C code via Cython, creating "test.c". I then compile with:
gcc -static test.c -I/home/me/Python-3.9.12/include/python3.9 -o test.exe -L/home/me/Python-3.9.12/lib -lpython3.9 -lpthread -lutil -lrt -lm -ldl
When I run "test.exe" I get this error:
Original error was: /home/me/NEWER/numpy/core/_multiarray_umath.cpython-39-x86_64-linux-gnu.so: undefined symbol: PyObject_SelfIter
What I don't understand is that the symbol PyObject_SelfIter is defined in libpython3.9.a which I link in as seen in the compilation line. Why doesn't this linking take care of the undefined symbol noted above? How can I get around this error?
2 notes:
I am linking statically because I want to run the resulting executable on an Android system
as a test, I tried compiling without the -static flag, and the executable still yields the same error
thanks for any tips.

Cannot find -lgcc

I am trying to follow an example for Cython builds from here http://blog.perrygeo.net/2008/04/19/a-quick-cython-introduction/, except my c1.pyx is simply helloworld.pyx with "print "Hello World"":
# this will create a c1.c file - the C source code to build a python extension
cython c1.pyx
# Compile the object file
gcc -c -fPIC -I/usr/include/python2.5/ c1.c
# Link it into a shared library
gcc -shared c1.o -o c1.so
The reason I am doing it in the command line is because my setup.py is giving me an error so I am doing it manually to see what is wrong.
The last step (gcc -shared c1.o -o c1.so) is where I hit the following error:
c:/users/MyName/anaconda/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../..
/x86_64-w64-mingw32/bin/ld.exe: cannot find -lgcc
c:/users/MyName/anaconda/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../..
/x86_64-w64-mingw32/bin/ld.exe: cannot find -lgcc
collect2.exe: error: ld returned 1 exit status
error: command 'C:\\Users\\MyName\\Anaconda\\Scripts\\gcc.bat' failed with exit st
atus 1
Any suggestions?
EDIT1: Thank you #mat for the edit. Also, I was noticing I didn't have Visual C++ 2008 installed on my computer. Not sure if Anaconda requires this for GCC and if this is the solution.

Linking Libraries using f2py

I have a fortran program that uses some library files. I am trying to link them along with the module file being created.
The library file I am trying to link is called ulib.a and is located in the directory /home/replace/lib/
The command I am using is:
f2py -L/home/replace/lib/ -lulib.a -c main.f -m progs
I am getting the following error:
/usr/bin/ld: cannot find -lulib.a
collect2: ld returned 1 exit status
/usr/bin/ld: cannot find -lulib.a
collect2: ld returned 1 exit status
I would appreciate any help!
Try leaving off the .a - I am reasonably sure that the linker already knows that libraries are .a so in your example it will be looking for ulib.a.a and failing.
I had to remove the extension from the library name and also provide the full path. For some reason providing the path using the -L argument did not work.
f2py -l/home/replace/lib/ulib -c main.f -m progs
The library should have the full name libxxx.a where xxx is the given name. Then do
f2py -L. -lxxx -c main.f90 -m progs
Note that only xxx comes after -l. If you create the library yourself remember to include -fPIC. For example, it could look like this:
gfortran -c -fPIC source1.f90 source2.f90
ar crs libxxx.a obj1.o obj2.o
f2py -L. -lxxx -c main.f90 -m progs
Found guidance in this example: https://modelingguru.nasa.gov/docs/DOC-2343

cannot find -lgsl and -lgslcblas

I am trying to compile a software called MRtrix in windows. It uses a python build script, (I have uploaded it here: http://pastebin.com/XnufSz53)
when I run this script I get the error pasted bellow.
I guess that the GSL libraries are not being found and I need to add a -L pointing to the library but because the compilation is being done by the python script I do not really now how to do this. Currently GnuWin is installed at C:\GnuWin32\
Thank you in advance,
Jesse
============================================================
ERROR: [LD] lib\mrtrix-0_2_11.dll
g++ -shared lib\image\format\base.o lib\math\vector.o lib\file\mmap.o lib\args.o
lib\image\format\dicom.o lib\file\dicom\select_cmdline.o lib\file\key_value.o l
ib\image\axis.o lib\image\format\mrtrix.o lib\image\interp.o lib\data_type.o lib
\point.o lib\image\mapper.o lib\file\dicom\element.o lib\file\dicom\mapper.o lib
\file\dicom\patient.o lib\file\dicom\quick_scan.o lib\image\object.o lib\mrtrix.
o lib\image\format\xds.o lib\file\dicom\dict.o lib\app.o lib\math\matrix.o lib\f
ile\config.o lib\image\format\mri.o lib\file\dicom\image.o lib\math\linalg.o lib
\file\dicom\study.o lib\file\dicom\series.o lib\image\name_parser.o lib\image\fo
rmat\list.o lib\file\dicom\tree.o lib\image\fft.o lib\image\header.o lib\image\f
ormat\analyse.o lib\image\format\nifti1.o -LC:/gtkmm64/lib -lglibmm-2.4 -lgobjec
t-2.0 -lsigc-2.0 -lgthread-2.0 -lglib-2.0 -lintl -lgsl -lgslcblas -lz -o lib\mrt
rix-0_2_11.dll
failed with output:
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lgsl
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lgslcblas
collect2.exe: error: ld returned 1 exit status
============================================================

Building CPython using clang invokes /usr/bin/ld for final link, and gets "/usr/bin/ld: error: libpython3.2m.a: malformed archive header name at 8"

I'm attempting to build CPython 3.2 using llvm's clang. It builds OK with gcc. I'm on Linux Mint 12.
The compile seems to go fine until the end, where it attempts to produce the ./python binary. The error I get is:
clang -pthread -Xlinker -export-dynamic -o python Modules/python.o libpython3.2m.a -lpthread -ldl -lutil -lm
/usr/bin/ld: error: libpython3.2m.a: malformed archive header name at 8
./Modules/python.c:25: error: undefined reference to 'PyMem_Malloc'
./Modules/python.c:27: error: undefined reference to 'PyMem_Malloc'
./Modules/python.c:51: error: undefined reference to '_Py_char2wchar'
./Modules/python.c:59: error: undefined reference to 'Py_Main'
./Modules/python.c:61: error: undefined reference to 'PyMem_Free'
./Modules/python.c:63: error: undefined reference to 'PyMem_Free'
./Modules/python.c:64: error: undefined reference to 'PyMem_Free'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've tried with the llvm 2.9 that's in my trusty Linux Mint 12 .deb repo, and with an SVN trunk of llvm from earlier today, but both give the same errors.
It occurs to me that perhaps things would go better if I could persuade clang to use llvm-link instead of /usr/bin/ld for linking, but I see nothing in the documentation about how to do that. Just setting $LD to llvm-link doesn't appear to help.
Those undefined references are likely red herrings: If I nm -o libpython3.2m.a (or llvm-nm -o libpython3.2m.a - both work), I can see that at least one of these symbols really is defined (according to nm of course - other tools could perhaps, and likely do, have other ideas).
Ultimately I want to generate llvm bitcode rather than an ELF binary, but it'd be a satisfying mini-milestone to get a working python ELF binary with llvm first.
I'm currently using the following for compilation:
export PATH=/usr/local/llvm/bin:$PATH
prefix=/usr/local/p3ib-3.2
export CC='clang'
export AR='llvm-ar'
export LD='llvm-link -emit-llvm-bc'
export RANLIB='llvm-ranlib'
./configure --prefix="$prefix" && make -j 3
Thanks!

Categories

Resources