unresolved external symbol PyMemoryView_GET_BUFFER
Hello,
I'm using the following setup to try to compile a C extension module
* Windows 11 x64
* CPython 3.12.4 x64
* Visual Studio Build Tools 2026 and 2022
### pyproject.toml
```toml
[build-system]
requires = ["scikit-build-core", "numpy>=2.0.0"]
build-backend = "scikit_build_core.build"
[tool.scikit-build]
cmake.version = ">=4.2"
metadata.version.provider = "scikit_build_core.metadata.regex"
metadata.version.input = "myapp/version.py"
wheel.packages = ["myapp"]
#wheel.py-api = "cp312"
```
### CMakeList.txt
```cmake
cmake_minimum_required(VERSION 4.2)
project(${SKBUILD_PROJECT_NAME} LANGUAGES C VERSION ${SKBUILD_PROJECT_VERSION})
# Ensure that option() calls in subdirectories respect normal variables
# set in this parent scope (e.g., disabling features in libdeflate).
# Without this, CMake would ignore values set via set(...) and always use
# the default provided in option(), which can lead to unexpected behavior.
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
include(CMakePrintHelpers)
find_package(
Python
REQUIRED
COMPONENTS
Interpreter
Development.Module
Development.SABIModule
${SKBUILD_SABI_COMPONENT}
NumPy
)
cmake_print_variables(Python3_VERSION Python3_VERSION_MAJOR Python3_VERSION_MINOR)
Python_add_library(cutils MODULE WITH_SOABI USE_SABI 3.12 myapp/xil/cutils.c)
# Add submodule libdeflate
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(LIBDEFLATE_COMPRESSION_SUPPORT ON)
set(LIBDEFLATE_GZIP_SUPPORT OFF)
set(LIBDEFLATE_BUILD_GZIP OFF)
add_subdirectory(ext/libdeflate EXCLUDE_FROM_ALL)
add_subdirectory(ext/lz4/build/cmake EXCLUDE_FROM_ALL)
add_subdirectory(ext/zstd/build/cmake EXCLUDE_FROM_ALL)
target_link_libraries(cutils PRIVATE Python::NumPy libdeflate::libdeflate_static lz4_static libzstd_static)
install(TARGETS cutils DESTINATION "myapp/xil")
```
When I run `python -m build -wheel` I get this error
```
* Creating isolated environment: venv+pip...
* Installing packages in isolated environment:
- numpy>=2.0.0
- scikit-build-core
* Getting build dependencies for wheel...
* Installing packages in isolated environment:
- cmake>=4.2
* Building wheel...
*** scikit-build-core 0.11.6 using CMake 4.2.1 (wheel)
*** Configuring CMake...
2026-01-23 14:46:58,610 - scikit_build_core - WARNING - Can't find a Python library, got libdir=None, ldlibrary=None, multiarch=None, masd=None
loading initial cache file C:\Users\user\AppData\Local\Temp\tmpt53zvnek\build\CMakeInit.txt
-- Building for: Visual Studio 18 2026
-- Selecting Windows SDK version 10.0.26100.0 to target Windows 10.0.22631.
-- The C compiler identification is MSVC 19.50.35723.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/18/BuildTools/VC/Tools/MSVC/14.50.35717/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found Python: C:/Users/user/AppData/Local/Temp/build-env-nqu5_tkx/Scripts/python.exe (found version "3.12.4") found components: Interpreter Development.Module Development.SABIModule NumPy
-- Python3_VERSION="" ; Python3_VERSION_MAJOR="" ; Python3_VERSION_MINOR=""
-- Creating build script for LZ4 version: 1.10.0
-- ZSTD VERSION: 1.6.0
-- CMAKE_INSTALL_PREFIX: C:/Users/user/AppData/Local/Temp/tmpt53zvnek/wheel/platlib
-- CMAKE_INSTALL_LIBDIR: lib
-- ZSTD_LEGACY_SUPPORT disabled
-- Multi-threading support enabled
-- Performing Test C_FLAG_MP
-- Performing Test C_FLAG_MP - Success
-- Performing Test C_FLAG_D_UNICODE
-- Performing Test C_FLAG_D_UNICODE - Success
-- Performing Test C_FLAG_DUNICODE
-- Performing Test C_FLAG_DUNICODE - Success
-- Configuring done (13.9s)
-- Generating done (0.4s)
-- Build files have been written to: C:/Users/user/AppData/Local/Temp/tmpt53zvnek/build
*** Building project with Visual Studio 18 2026...
MSBuild version 18.0.5+e22287bf1 for .NET Framework
C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\MSBuild\Microsoft\VC\v180\Microsoft.CppBuild.targets(558,5): warning MSB8029: The Intermediate directory or Output directory cannot reside under the Temporar
y directory as it could lead to issues with incremental build. [C:\Users\user\AppData\Local\Temp\tmpt53zvnek\build\ZERO_CHECK.vcxproj]
1>Checking Build System
C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\MSBuild\Microsoft\VC\v180\Microsoft.CppBuild.targets(558,5): warning MSB8029: The Intermediate directory or Output directory cannot reside under the Temporar
y directory as it could lead to issues with incremental build. [C:\Users\user\AppData\Local\Temp\tmpt53zvnek\build\ext\libdeflate\libdeflate_static.vcxproj]
Building Custom Rule C:/Users/user/01__Workspace/myapp/ext/libdeflate/CMakeLists.txt
cpu_features.c
utils.c
deflate_compress.c
deflate_decompress.c
adler32.c
zlib_compress.c
zlib_decompress.c
Generating Code...
cpu_features.c
libdeflate_static.vcxproj -> C:\Users\user\AppData\Local\Temp\tmpt53zvnek\build\ext\libdeflate\Release\deflatestatic.lib
C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\MSBuild\Microsoft\VC\v180\Microsoft.CppBuild.targets(558,5): warning MSB8029: The Intermediate directory or Output directory cannot reside under the Temporar
y directory as it could lead to issues with incremental build. [C:\Users\user\AppData\Local\Temp\tmpt53zvnek\build\ext\zstd\build\cmake\lib\libzstd_static.vcxproj]
Building Custom Rule C:/Users/user/01__Workspace/myapp/ext/zstd/build/cmake/lib/CMakeLists.txt
debug.c
entropy_common.c
error_private.c
fse_decompress.c
pool.c
threading.c
xxhash.c
zstd_common.c
fse_compress.c
hist.c
huf_compress.c
zstd_compress.c
zstd_compress_literals.c
zstd_compress_sequences.c
zstd_compress_superblock.c
zstd_double_fast.c
zstd_fast.c
zstd_lazy.c
zstd_ldm.c
zstd_opt.c
zstd_preSplit.c
zstdmt_compress.c
huf_decompress.c
zstd_ddict.c
zstd_decompress.c
zstd_decompress_block.c
cover.c
divsufsort.c
fastcover.c
zdict.c
libzstd_static.vcxproj -> C:\Users\user\AppData\Local\Temp\tmpt53zvnek\build\ext\zstd\build\cmake\lib\Release\zstd_static.lib
C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\MSBuild\Microsoft\VC\v180\Microsoft.CppBuild.targets(558,5): warning MSB8029: The Intermediate directory or Output directory cannot reside under the Temporar
y directory as it could lead to issues with incremental build. [C:\Users\user\AppData\Local\Temp\tmpt53zvnek\build\ext\lz4\build\cmake\lz4_static.vcxproj]
Building Custom Rule C:/Users/user/01__Workspace/myapp/ext/lz4/build/cmake/CMakeLists.txt
lz4.c
lz4file.c
lz4frame.c
lz4hc.c
xxhash.c
Generating Code...
lz4_static.vcxproj -> C:\Users\user\AppData\Local\Temp\tmpt53zvnek\build\ext\lz4\build\cmake\Release\lz4.lib
C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\MSBuild\Microsoft\VC\v180\Microsoft.CppBuild.targets(558,5): warning MSB8029: The Intermediate directory or Output directory cannot reside under the Temporar
y directory as it could lead to issues with incremental build. [C:\Users\user\AppData\Local\Temp\tmpt53zvnek\build\cutils.vcxproj]
Building Custom Rule C:/Users/user/01__Workspace/myapp/CMakeLists.txt
cutils.c
C:\Users\user\01__Workspace\myapp\myapp\xil\cutils.c(814,12): warning C4047: '=': 'Py_buffer *' differs in levels of indirection from 'int' [C:\Users\user\AppData\Local\Temp\tmpt53zvnek\build\cutils.vcxproj]
C:\Users\user\01__Workspace\myapp\myapp\xil\cutils.c(1414,19): warning C4047: 'initializing': 'Py_buffer *' differs in levels of indirection from 'int' [C:\Users\user\AppData\Local\Temp\tmpt53zvnek\build\cutils
.vcxproj]
C:\Users\user\01__Workspace\myapp\myapp\xil\cutils.c(1924,19): warning C4047: 'initializing': 'Py_buffer *' differs in levels of indirection from 'int' [C:\Users\user\AppData\Local\Temp\tmpt53zvnek\build\cutils
.vcxproj]
Creating library C:/Users/user/AppData/Local/Temp/tmpt53zvnek/build/Release/cutils.lib and object C:/Users/user/AppData/Local/Temp/tmpt53zvnek/build/Release/cutils.exp
cutils.obj : error LNK2019: unresolved external symbol PyMemoryView_GET_BUFFER referenced in function recorder_acquire [C:\Users\user\AppData\Local\Temp\tmpt53zvnek\build\cutils.vcxproj]
C:\Users\user\AppData\Local\Temp\tmpt53zvnek\build\Release\cutils.pyd : fatal error LNK1120: 1 unresolved externals [C:\Users\user\AppData\Local\Temp\tmpt53zvnek\build\cutils.vcxproj]
```
On the other hand I can compile the same code without issues if I use `setup.py` and `setuptools`
### setup.py
```python
"""
myapp setup file
"""
# To use a consistent encoding
from codecs import open
from os import path
# Always prefer setuptools over distutils
from setuptools import Extension, find_packages, setup
try:
import numpy
except:
pass
def get_export_symbols(self, ext):
parts = ext.name.split(".")
print("parts", parts)
if parts[-1] == "__init__":
initfunc_name = "PyInit_" + parts[-2]
else:
initfunc_name = "PyInit_" + parts[-1]
here = path.abspath(path.dirname(__file__))
# Get the long description from the README file
long_description = open("README.md", "rt").read()
with open("requirements.txt") as f:
required = f.read().splitlines()
with open(path.join("myapp", "version.py"), "r") as f:
for line in f:
if line.startswith("__version__"):
version = line.split("=")[-1].strip().strip('"')
break
setup(
name="myapp",
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version=version,
description="GUI app",
long_description=long_description,
long_description_content_type="text/markdown",
# The project's main homepage.
url="",
# Author details
author="Daniel Hrisca",
author_email="daniel.hrisca@gmail.com",
# Choose your license
license="Proprietary",
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
"Development Status :: 5 - Production/Stable",
# Indicate who your project is intended for
"Intended Audience :: Developers",
"Topic :: Software Development",
"Topic :: Scientific/Engineering",
# Pick your license as you wish (should match "license" above)
"License :: Other/Proprietary License",
# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
"Programming Language :: Python :: 3.12",
],
# What does your project relate to?
keywords="gui automotive",
# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
packages=find_packages(exclude=["contrib", "docs", "test"]),
# Alternatively, if you want to distribute just a my_module.py, uncomment
# this:
# py_modules=["my_module"],
# List run-time dependencies here. These will be installed by pip when
# your project is installed. For an analysis of "install_requires" vs pip's
# requirements files see:
# https://packaging.python.org/en/latest/requirements.html
install_requires=required,
# List additional groups of dependencies here (e.g. development
# dependencies). You can install these using the following syntax,
# for example:
# $ pip install -e .[dev,test]
extras_require={},
# If there are data files included in your packages that need to be
# installed, specify them here. If using Python 2.6 or less, then these
# have to be included in MANIFEST.in as well.
package_data={"myapp": ["myapp/*.ui", "myapp/*.qrc", "myapp/*.png", "myapp/*.a2l", "myapp/*.dll", "myapp/*.json"]},
include_package_data=True,
# Although 'package_data' is the preferred approach, in some case you may
# need to place data files outside of your packages. See:
# http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # noqa
# In this case, 'data_file' will be installed into '<sys.prefix>/my_data'
# data_files=[('my_data', ['data/data_file'])],
# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and allow
# pip to create the appropriate form of executable for the target platform.
entry_points={
"console_scripts": [
"myapp=myapp.gui:main",
],
},
ext_package="myapp.xil",
ext_modules=[Extension("cutils", ["myapp/xil/cutils.c"], include_dirs=[numpy.get_include()])],
)
```
Any idea what could be the reason for the error?
Thanks!
1 条评论