0

My Setup

I am trying to develop a Python 3 library as a C extension. I am on Windows 10, and I have Python 3.5.2 64 bit installed as my only Python distribution. I also have Visual Studio 2017 installed.

This library relies on glew and glfw. I believe I have installed the libraries properly, I've installed their headers in

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\

their .lib files in

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib

and their .dll files in

C:\Windows\System32

My setup.py file looks essentially like this:

module = Extension('my_library',
                   library_dirs=['C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib'],
                   libraries=['glew32', 'glfw3'],
                   sources=['my_library/c/my_library.c'])

setup(name="MyLibrary",
      version="0.1",
      description="My Python 3 Library",
      ext_modules=[module])

The Problem

When I run python setup.py build, I receive

MSVCRT.lib(chkstk.obj) : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1112

Okay, so I'm really not sure what that means, as my machine is 64 bit... but it is x86 architecture. But I assumed that meant that I was not targeting 64 bit, so I read online and found this answer, which says to run

set DISTUTILS_USE_SDK=1
set MSSdk=1

Using the "Visual Studio 2008 x64 Win64 Command Prompt", which I don't have. I tried the other command prompts, and they either give the same error, or they give

Compiling Desktop applications for the ARM platform is not supported.

When I try the setting DISTUTILS_USE_SDK method on the regular command prompt, I receive the error

python\python35\include\pyconfig.h(68): fatal error C1083: Cannot open include file: 'io.h': No such file or directory

The Question

I'm really not sure where to go from here. I just want to be able to link the glew/glfw. The module was originally compiling and working properly when the glew/glfw were not being included/linked.

Thank you for any advice

Enrico Borba
  • 1,877
  • 2
  • 14
  • 26
  • You need to install the 64 bit versions of glew and glfw. Your architecture is `x86_64` not `x86`. In windows they call `x86_64` as `x64`. – alvits Jun 13 '17 at 01:42
  • I did install the 64 bit versions of glew and glfw. And yes you are correct, I guess I meant I had the x86 instruction set. I will reinstall the 64 bit versions just to be sure. – Enrico Borba Jun 13 '17 at 01:43
  • This is the error message `module machine type 'X86' conflicts with target machine type 'x64'`. Clearly you have a mixed architecture. – alvits Jun 13 '17 at 01:45
  • I made sure the libraries installed are 64 bit. I also tried something new. I tried linking the libraries without having the source include them. Aka, the source doesn't need them, but I wanted to see if just linking them would cause any errors, and it did. I get `unresolved external symbol __security_check_cookie` and `error LNK2001: unresolved external symbol _DllMainCRTStartup`. Please tell me if there is any more information you would like to know. – Enrico Borba Jun 13 '17 at 02:04
  • The error you are seeing means you didn't link it with `MSVCRT`. This will tell you all about it https://msdn.microsoft.com/en-us/library/988ye33t.aspx – alvits Jun 13 '17 at 02:07
  • I added `msvcrt.lib` during the linking phase and I am still getting the same errors... – Enrico Borba Jun 13 '17 at 02:11
  • I found this solution from microsoft knowledegbase. This could resolve your original issue https://www.altera.com/support/support-resources/knowledge-base/solutions/rd11052014_333.html – alvits Jun 13 '17 at 02:14
  • Possible duplicate of [fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'](https://stackoverflow.com/questions/3563756/fatal-error-lnk1112-module-machine-type-x64-conflicts-with-target-machine-typ) – alvits Jun 13 '17 at 02:16
  • I found those as well, `vcvars64.bat` doesn't exist in the Visual Studio 14 installation. `vcvarsall.bat` exists with these options `x86 | amd64 | x86_amd64 | x86_arm | amd64_x86 | amd64_arm`. For the second link, I'm not using visual studio, I just want to understand everything through CLI before moving to an IDE. – Enrico Borba Jun 13 '17 at 02:23
  • Even with command line, you still need to set your environment variables to select the correct architecture. You should run vcvarsall.bat with x86_amd64 option. – alvits Jun 13 '17 at 16:05
  • Yes I have done this, that is what I meant by the previous comment. I receive the same error. I feel like I have set up the build tools incorrectly – Enrico Borba Jun 13 '17 at 17:13

0 Answers0