8

I'm trying to compile pybind11 on a Windows machine that has VisualStudio 2015 installed. I also have python 3.5.3 64bit installed, and cmake 2.8.12. I get the error:

CMake Error at tools/FindPythonLibsNew.cmake:122 (message):
  Python config failure: Python is 64-bit, chosen compiler is 32-bit
Call Stack (most recent call first):
  tools/pybind11Tools.cmake:16 (find_package)
  CMakeLists.txt:28 (include)

I did not "choose" the compiler to be 32-bit, and looking at the CMakeLists.txt, I did not find any place to specify which compiler to run. So how to I tell pybind11/cmake to compile for 64 bit?

Periodic Maintenance
  • 1,698
  • 4
  • 20
  • 32
  • You have to choose your compiler version from either VS2015 (if you're compiling from there) or from the command line prompt. Also, it is highly recommended to upgrade your cmake version. – utopia Jul 30 '17 at 10:25
  • @utopia, I'm building from the command line, how to I "choose" the compiler to be 64 instead of 32? Do I need to add something to the CMakeLists.txt file? – Periodic Maintenance Jul 30 '17 at 14:31

3 Answers3

12

You should specify the 64-bit VS compiler like so:

cmake "/path/to/src/" -G"Visual Studio 14 2015 Win64"

Otherwise it selects the 32-bit by default.

Caleb
  • 870
  • 1
  • 10
  • 21
  • 1
    OK that works although it needed some workout: the comman should be cmake .. .. -G"Visual Studio 14 2015 Win64" AND cmake should be upgraded to 3.x since 2.8.12 does not know about VS 2015. (pybind11 docs state that 2.8.12 is needed) – Periodic Maintenance Jul 31 '17 at 08:00
  • 2
    In my case Windows 10 Visual Studio Community `cmake CMakeLists.txt -G"Visual Studio 16 2019" -A x64` – imbr Aug 30 '19 at 18:04
  • simply doing ```cmake .. -G"Visual Studio 14 2015 Win64"``` did the trick for me. thanks a lot – Hossein Mar 27 '20 at 09:21
3

If you are using the Ninja generator and you have this error make sure you run the VS Dev command prompt in 64-bit mode:

VsDevCmd.bat arch=amd64 && cmake <options> ... 
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
2

You can either do :

cmake .. -G"Visual Studio 14 2015 Win64"
cmake --build . --config Release --target check

or based on this quote from the Compiling the test cases for windows section here:

If all tests fail, make sure that the Python binary and the testcases are compiled for the same processor type and bitness (i.e. either i386 or x86_64). You can specify x86_64 as the target architecture for the generated Visual Studio project using cmake -A x64 ..

You can do :

cmake -A x64 ..
cmake --build . --config Release --target check
Hossein
  • 24,202
  • 35
  • 119
  • 224