pybind / pybind11

Seamless operability between C++11 and Python
https://pybind11.readthedocs.io/
Other
15.7k stars 2.1k forks source link

[Bug]: Pybind failed to build due to error LNK2019 on windows with MSVC Target ARM64 #5222

Open spacelg opened 4 months ago

spacelg commented 4 months ago

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

19a6b9f

Problem description

Hi,

Pybind failed to build due to error LNK2019 on windows with MSVC Target ARM64. It can be reproduced on commit 19a6b9f on master branch. Could you please help look at this issue? Thanks in advance.

Steps to reproduce the behavior:

  1. git clone https://github.com/pybind/pybind11 C:\gitP\pybind\pybind11
  2. Open a VS2022 x64 cmd
  3. "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" -host_arch=amd64 -arch=arm64
  4. cd C:\gitP\pybind\pybind11 && mkdir build_arm64
  5. cmake -G "Visual Studio 17 2022" -A arm64 -DCMAKE_SYSTEM_VERSION=10.0.22621.0 -DPython_EXECUTABLE=C:\Python311\python.exe ..
  6. msbuild /m /p:Platform=arm64 /p:Configuration=Release pybind11.sln /t:Rebuild

Build.log

Error Message: 17>CustomBuild: Internal cmake changing into directory: C:/gitP/pybind/pybind11/build_arm64/tests/test_cmake_build/subdirectory_target ======== CMake output ====== Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.20348. The CXX compiler identification is MSVC 19.41.34101.96 Detecting CXX compiler ABI info Detecting CXX compiler ABI info - done Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.40.33807/bin/Hostx64/arm64/cl.exe - skipped Detecting CXX compile features Detecting CXX compile features - done pybind11 v2.13.0 dev1 Found Python: C:\Python311\python.exe (found suitable version "3.11.4", minimum required is "3.6") found components: Interpreter Development.Module Development.Embed Performing Test HAS_MSVC_GL_LTCG Performing Test HAS_MSVC_GL_LTCG - Success Configuring done (3.6s) Generating done (0.0s) Build files have been written to: C:/gitP/pybind/pybind11/build_arm64/tests/test_cmake_build/subdirectory_target ======== End CMake output ====== Change Dir: 'C:/gitP/pybind/pybind11/build_arm64/tests/test_cmake_build/subdirectory_target'

     Run Build Command(s): "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/MSBuild/Current/Bin/amd64/MSBuild.exe" check_subdirectory_target.vcxproj /p:Configuration=Release /p:Platform=arm64 /p:VisualStudioVersion=17.0 /v:m
     MSBuild version 17.10.4+10fbfbf2e for .NET Framework

       1>Checking Build System
       Building Custom Rule C:/gitP/pybind/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt
       main.cpp
          Creating library C:/gitP/pybind/pybind11/build_arm64/tests/test_cmake_build/subdirectory_target/Release/test_cmake_build.lib and object C:/gitP/pybind/pybind11/build_arm64/tests/test_cmake_build/subdirectory_target/Release/test_cmake_build.exp
17>main.obj : error LNK2019: unresolved external symbol __imp_PyMem_Calloc referenced in function "public: void __cdecl pybind11::detail::instance::allocate_layout(void)" (?allocate_layout@instance@detail@pybind11@@QEAAXXZ) [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\subdirectory_target\test_subdirectory_target.vcxproj] [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\test_build_subdirectory_target.vcxproj]
17>main.obj : error LNK2019: unresolved external symbol __imp_PyMem_Free referenced in function "public: void __cdecl pybind11::detail::instance::deallocate_layout(void)" (?deallocate_layout@instance@detail@pybind11@@QEAAXXZ) [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\subdirectory_target\test_subdirectory_target.vcxproj] [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\test_build_subdirectory_target.vcxproj]
17>main.obj : error LNK2019: unresolved external symbol __imp_PyType_IsSubtype referenced in function "private: bool __cdecl pybind11::detail::string_caster<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,0>::load_raw<char>(class pybind11::handle)" (??$load_raw@D@?$string_caster@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@$0A@@detail@pybind11@@AEAA_NVhandle@2@@Z) [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\subdirectory_target\test_subdirectory_target.vcxproj] [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\test_build_subdirectory_target.vcxproj]
17>main.obj : error LNK2019: unresolved external symbol __imp_PyType_Ready referenced in function "struct _typeobject * __cdecl pybind11::detail::make_default_metaclass(void)" (?make_default_metaclass@detail@pybind11@@YAPEAU_typeobject@@XZ) [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\subdirectory_target\test_subdirectory_target.vcxproj] [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\test_build_subdirectory_target.vcxproj]
17>main.obj : error LNK2019: unresolved external symbol __imp_PyObject_Repr referenced in function "protected: static struct _object * __cdecl pybind11::cpp_function::dispatcher(struct _object *,struct _object *,struct _object *)" (?dispatcher@cpp_function@pybind11@@KAPEAU_object@@PEAU3@00@Z) [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\subdirectory_target\test_subdirectory_target.vcxproj] [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\test_build_subdirectory_target.vcxproj]
17>main.obj : error LNK2019: unresolved external symbol __imp_PyObject_Str referenced in function "public: __cdecl pybind11::str::str(class pybind11::handle)" (??0str@pybind11@@QEAA@Vhandle@1@@Z) [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\subdirectory_target\test_subdirectory_target.vcxproj] [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\test_build_subdirectory_target.vcxproj]
17>main.obj : error LNK2019: unresolved external symbol __imp_PyObject_GetAttrString referenced in function "public: class pybind11::module_ & __cdecl pybind11::module_::def<class <lambda_a0eb0843473aca4739996e7d1687e1ea> >(char const *,class <lambda_a0eb0843473aca4739996e7d1687e1ea> &&)" (??$def@V<lambda_a0eb0843473aca4739996e7d1687e1ea>@@$$V@module_@pybind11@@QEAAAEAV01@PEBD$$QEAV<lambda_a0eb0843473aca4739996e7d1687e1ea>@@@Z) [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\subdirectory_target\test_subdirectory_target.vcxproj] [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\test_build_subdirectory_target.vcxproj]
17>main.obj : error LNK2019: unresolved external symbol __imp_PyObject_SetAttrString referenced in function "struct _typeobject * __cdecl pybind11::detail::make_default_metaclass(void)" (?make_default_metaclass@detail@pybind11@@YAPEAU_typeobject@@XZ) [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\subdirectory_target\test_subdirectory_target.vcxproj] [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\test_build_subdirectory_target.vcxproj]
17>main.obj : error LNK2019: unresolved external symbol __imp_PyObject_HasAttrString referenced in function "public: void __cdecl pybind11::module_::add_object(char const *,class pybind11::handle,bool)" (?add_object@module_@pybind11@@QEAAXPEBDVhandle@2@_N@Z) [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\subdirectory_target\test_subdirectory_target.vcxproj] [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\test_build_subdirectory_target.vcxproj]
17>main.obj : error LNK2019: unresolved external symbol __imp_PyObject_ClearWeakRefs referenced in function "void __cdecl pybind11::detail::clear_instance(struct _object *)" (?clear_instance@detail@pybind11@@YAXPEAU_object@@@Z) [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\subdirectory_target\test_subdirectory_target.vcxproj] [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\test_build_subdirectory_target.vcxproj]
17>main.obj : error LNK2019: unresolved external symbol __imp__Py_Dealloc referenced in function "public: class pybind11::object __cdecl pybind11::detail::object_api<class pybind11::detail::accessor<struct pybind11::detail::accessor_policies::str_attr> >::operator()<1,class pybind11::handle const &>(class pybind11::handle const &)const " (??$?R$00AEBVhandle@pybind11@@@?$object_api@V?$accessor@Ustr_attr@accessor_policies@detail@pybind11@@@detail@pybind11@@@detail@pybind11@@QEBA?AVobject@2@AEBVhandle@2@@Z) [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\subdirectory_target\test_subdirectory_target.vcxproj] [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\test_build_subdirectory_target.vcxproj]
17>main.obj : error LNK2019: unresolved external symbol __imp__PyType_Lookup referenced in function pybind11_meta_getattro [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\subdirectory_target\test_subdirectory_target.vcxproj] [C:\gitP\pybind\pybind11\build_arm64\tests\test_cmake_build\test_build_subdirectory_target.vcxproj]

Reproducible example code

No response

Is this a regression? Put the last known working version here if it is.

Not a regression

jgautier-anssi commented 1 day ago

I confirm this is an issue with pybind11 & ARM64 currently... I was able to link and load my python module by making the following steps (VS generator): 1- change the path to python from "amd64" to "arm64" in the link input (from "C:\Program Files\Python313\libs\python313.lib" to "C:\Program Files\Python313-arm64\libs\python313.lib" 2- build & link 3- rename generated file from MyModule.cp313-win_amd64.pyd to MyModule.cp313-win_arm64.pyd

Unfortunately, I am not fluent enough in cmake to submit a PR for this issue :-(