Short path problem on Windows
When paths from C:\Program Files\WindowsApps
are used, it is not possible to shorten them - the call to GetShortPathNameW
fails with ERROR_ACCESS_DENIED
. This is what NMake Makefile generator uses and the generated makefiles fail to compile - the shortened paths from WindowsApps
folder are empty.
Use case:
- Windows 11 22H2
- Python from MS Store installed (3.11 in my case)
- Microsoft Visual Studio
- CMake project with Python and NMake Makefile generator
Steps to reproduce:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.26)
project(mytest)
find_package (Python COMPONENTS Development)
set(SRCS PyTest.c)
add_library(mytest SHARED ${SRCS})
include_directories("${Python_INCLUDE_DIRS}")
#include_directories("C:/Program Files/WindowsApps/PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0/include")
target_link_libraries(mytest ${Python_LIBRARIES})
set_target_properties(
mytest
PROPERTIES
PREFIX ""
OUTPUT_NAME "mytest"
LINKER_LANGUAGE C
)
PyTest.c:
#include <Python.h>
// This is the definition of a method
static PyObject* division(PyObject *self, PyObject *args) {
long dividend, divisor;
if (!PyArg_ParseTuple(args, "ll", ÷nd, &divisor)) {
return NULL;
}
if (0 == divisor) {
PyErr_Format(PyExc_ZeroDivisionError, "Dividing %d by zero!", dividend);
return NULL;
}
return PyLong_FromLong(dividend / divisor);
}
// Exported methods are collected in a table
PyMethodDef method_table[] = {
{"division", (PyCFunction) division, METH_VARARGS, "Method docstring"},
{NULL, NULL, 0, NULL} // Sentinel value ending the table
};
// A struct contains the definition of a module
PyModuleDef mytest_module = {
PyModuleDef_HEAD_INIT,
"mytest", // Module name
"This is the module docstring",
-1, // Optional size of the module state memory
method_table,
NULL, // Optional slot definitions
NULL, // Optional traversal function
NULL, // Optional clear function
NULL // Optional module deallocation function
};
// The module init function
PyMODINIT_FUNC PyInit_mytest(void) {
return PyModule_Create(&mytest_module);
}
Now create folder build
and from inside execute cmake -G "Visual Studio 17 2022" -A x64 ..
. The following nmake
will fail - check file build/CMakeFiles/mytest.dir/flags.make
and inspect C_INCLUDES
- there is empty string.
C_INCLUDES = -I""
Edited by Oldřich Jedlička