pybind / pybind/pybind11

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

Open
#5,222 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with the listed VS2022 ARM64 CMake and MSBuild commands, using the build log as the reference. Review tests/test_cmake_build/subdirectory_target/CMakeLists.txt and the generated target involved in the unresolved Python symbols. Done means the ARM64 Release rebuild of pybind11.sln completes without the reported LNK2019 errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, python
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.