Error when Compiling Cython into 32bit app - python

I have python code that I am using Cython to convert to C (in order to call from C# 32bit application).
When I use MSVC x86 Native Tool Command prompt to run:
python setup.py build_ext --inplace --compiler=msvc
I get the error:
python38.lib(python38.dll) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86'
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX86\x86\link.exe' failed with exit status 1112
When I use MSVC X64 Native Tool command prompt, I try to first run: setenv /x86 but setenv is not recognized. However, I can build as x64 successfully. When I compile the resulting c code as dll to call from C#, it is not a surprise that I get the following memory access violation:
System.AccessViolationException
HResult=0x80004003
Message=Attempted to read or write protected memory.
This is often an indication that other memory is corrupt.
I was wondering how to solve this issue, and be able to build for x86.
Thanks very much in advance!

Related

Cross-compiling for Windows Python error

I try to cross-compile libplist (https://github.com/libimobiledevice/libplist) for 64-bit Windows and create a DLL from it. I downloaded mingw-w64 for Linux subsystem on Windows 10 (Ubuntu 14.04 bash) and set the environment variables (CC, CXX, CPP, RANLIB). I use ./autogen.sh --host=x86_64-w64-mingw32 to configure package. However it exits with the error:
configure:16825: error:
Could not link test program to Python. Maybe the main Python library has been
installed in some non-standard library path. If so, pass it to configure,
via the LDFLAGS environment variable.
Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
============================================================================
ERROR!
You probably have to install the development version of the Python package
for your distribution. The exact name of this package varies among them.
============================================================================
In config.log it says:
configure:16813: x86_64-w64-mingw32-gcc -o conftest.exe -g -O2 -I/usr/include/python2.7 -I/usr/include/x86_64-linux-g$
In file included from /usr/include/python2.7/Python.h:8:0,
from conftest.c:33:
/usr/include/python2.7/pyconfig.h:78:3: error: #error unknown multiarch location for pyconfig.h
# error unknown multiarch location for pyconfig.h
^
In file included from /usr/include/python2.7/pyport.h:4:0,
from /usr/include/python2.7/Python.h:58,
from conftest.c:33:
/usr/include/python2.7/pyconfig.h:78:3: error: #error unknown multiarch location for pyconfig.h
# error unknown multiarch location for pyconfig.h
^
In file included from /usr/include/python2.7/pymath.h:4:0,
from /usr/include/python2.7/Python.h:77,
from conftest.c:33:
/usr/include/python2.7/pyconfig.h:78:3: error: #error unknown multiarch location for pyconfig.h
# error unknown multiarch location for pyconfig.h
^
configure:16813: $? = 1
It doesn't return this error when I try to compile it for Linux, so I thought that it's because it needs python libraries compiled for Windows x86_64. I copied the appropriate files from Windows from C:/Python27/include and tried to set environment variable for configuration LDFLAGS="-L/path/to/python/include" and PKG_CONFIG_PATH=/path/to/python/include separately. Neither of them worked. I also noticed, that in C:/Python27/include there was also a file called pyconfig.h.Why does the script uses the one installed on Linux? Is there a way I could force it to use the other one?
My main objective would be to make a 64-bit Windows DLL from libusbmuxd (https://github.com/libimobiledevice/libusbmuxd), but it needs libplist to be compiled too. How could I solve this issue? Thanks for the answers in advance.
You can try libimobiledevice-win32. Although the name is a bit confusing, it builds 32-bit and 64-bit Windows versions of libimobiledevice.
You can compile libplist, libusbmuxd, libimobildevice and the various utilities for Windows using Visual Studio, avoiding the need to cross compile.
The company I work for, Quamotion, maintains libimobiledevice-win32 and we try to stay on track with the latest upstream changes.
You can download precompiled versions from the CI build, see e.g. https://ci.appveyor.com/project/qmfrederik/imobiledevice-net/build/artifacts for zip files which contain the latest bits.

["CompileError: command 'c:\\\\mingw\\\\bin\\\\gcc.exe' failed with exit status 1\n"]

I tried all the options to make mingw32 compiler work, but every time I get this error
CompileError: command 'c:\\\\mingw\\\\bin\\\\gcc.exe' failed with exit status 1\n
and don't know how to fix it.
Steps that I have done:
Installed Anaconda 2.7 win 32 bits (Although my computer is 64 bits, but since the python is working I assume it should not be a problem)
Installed Microsoft Visual C++ Compiler for Python 2.7
Installed mingw32 and added to system environment path (I tested at command prompt by calling gcc and it is working)
Created distutils.cfg in C:\Python27\Lib\distutils folder
I appreciate if someone could help me on this.

Python: Warning and after Error using SCons

I am trying to install the openWSN platform on my MAC OS X, to be able to run tests in a simulated (or real) sensors network. For that, is necessary the Python development headers and libraries. In fact, I think the headers are already installed, as I have already downloaded XCode, Command Line Tools, Homebrew, and I already downloaded the Python.
I am using SCons to construct the software application.
The big problem is that when I type this command on the terminal:
$ scons board=python toolchain=gcc oos_openwsn
The processing seems to be going well, when I receive the following warning and error:
File "/Users/stage/Desktop/openwsn/openwsn-fw/SConscript", line 578, in sconscript_scanner
scons: done reading SConscript files.
scons: Building targets ...
Linking (shared) firmware/openos/projects/common/oos_openwsn.so
**ld: warning: directory not found for option '-L/Library/Frameworks/Python.framework/Versions/2.7/libs'**
ld: unknown option: -Bsymbolic-functions
clang: error: linker command failed with exit code 1 (use -v to see invocation)
scons: *** [firmware/openos/projects/common/oos_openwsn.so] Error 1
scons: building terminated because of errors.
The problem to me seems to be in the libs folder, as if the scons could not find this folder, and cannot proceed.
I checked the SCons files for the project https://github.com/openwsn-berkeley/openwsn-fw that you seem to be using. I don't see any hints that the compilation and installation of sources is supported for MacOS. Are you sure that the project supports your OS? If you are, you should consider asking the project's maintainers for help, e.g. via ML or IRC.
The main error in your output above is the "ld: unknown option: -Bsymbolic-functions". Since you specified "toolchain=gcc" in your call, this is what the build expects...but you don't seem to have a proper gcc installed. The clang compiler that is found instead doesn't know the provided command-line option, and stops with an error.

Compiling python-mcrypt in win32?

Um, I'm stumped and really stuck (+_+) here after googling many sites. I'm using mingw32-gcc.exe from Dev-c++ compiler and currently following instructions from this site.
Every time I try here's the result:
C:\Python26>python c:\python26\python-mcrypt-1.1\setup.py install
running install
running build
running build_ext
error: don't know how to compile C/C++ code on platform 'nt' with 'mingw32-gcc.exe' compiler
I've edited the distuils.cfg file in my c:\python26\lib\distuils\distuils.cfg with this parameter
[build]
compiler = mingw32-gcc.exe
Any ideas would be appreciated!
You installed python outside of a compilation environment valids one include cygwin or mingw32 (wich is used by Dev-C++).
To use the command-line mode, you need to find the your compiler installation and find bat script which launch the shell with the proper parameters (This is needed for bith cygwin and mingw).
The alternative is to use Microsft solution for that problem.

Compiling Python Extension On Windows With Cygwin

I have been having a terrible time trying to compile a python extension - hopefully someone can help.
I initially tried executing 'python.exe setup.py build' but received the error: 'Python was built Visual Studio 2003; extensions must be built with a compiler that can generate compatible binaries...".
So I then downloaded Cygwin, and have tried sending the switch '-c mingw32'. A few lines were written into the console - then I get the error message: command 'gcc' failed: Permission denied.
I was initially using the Visual Studio 2010 Command Line to do this, but tried with bash and got the same result.
I have spent a considerable amount of time researching the issue, and it appears Cygwin uses symlinks for gcc and g++, and windows doesn't understand how to handle this.
How exactly can I force setup.py to use gcc-3.exe instead of the gcc.exe symlink?
I know it's inelegant, but you can rename the symlink and copy gcc-3.exe to gcc.exe. That worked for me when I used Cygwin's gcc. You might want to switch to the mingw64-i686 (or mingw64-x86_64) package to get gcc 4.5.3, or just install MinGW-w64 separately for compiling under Windows.
Also, you can permanently configure distuilts in PythonXX\Lib\distutils\distutils.cfg:
[build]
compiler = mingw32
[build_ext]
compiler = mingw32
[build_clib]
compiler = mingw32

Categories