Skip to content

[Fix / Workaround] Building Python module on Windows fails (Missing ZLIB & LNK1149 Error) #70

@Enndee

Description

@Enndee

When trying to build the spz python module on Windows via pip install git+https://github.com/nianticlabs/spz.git, the installation fails due to two main issues:

  1. CMake Error: Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
  2. MSVC Linker Error: LINK : fatal error LNK1149: output filename matches input filename '...\Release\spz.lib' (because the static library and the python module try to generate a .lib file with the exact same name).

Here is a step-by-step guide/fix for Windows users to build the project successfully:
Step 1: Install ZLIB via vcpkg

Windows doesn't ship with ZLIB natively. The easiest way to provide it to CMake is using Microsoft's vcpkg.
Open your Visual Studio Developer Command Prompt and run:

cd %USERPROFILE%
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg install zlib:x64-windows

Set the toolchain environment variable so CMake knows where to find vcpkg:

set CMAKE_TOOLCHAIN_FILE=%USERPROFILE%\vcpkg\scripts\buildsystems\vcpkg.cmake

Step 2: Fix the LNK1149 Target Name Collision

Clone the repository locally:

git clone https://github.com/nianticlabs/spz.git spz_local
cd spz_local

Open CMakeLists.txt in the root folder. You need to rename the output of the static library so it doesn't conflict with the Python extension spz.lib.
Find this section:

# create the library and configure it
add_library(spz ${spz_sources})
add_library(spz::spz ALIAS spz)

Add set_target_properties in between, like this:

#```
create the library and configure it
add_library(spz ${spz_sources})
set_target_properties(spz PROPERTIES OUTPUT_NAME "spz_static") # <--- ADD THIS LINE
add_library(spz::spz ALIAS spz)


Step 3: Build and Install

Run the pip install command inside the local directory, pointing CMake to the vcpkg toolchain:

`pip install . --config-settings=cmake.define.CMAKE_TOOLCHAIN_FILE="%USERPROFILE%\vcpkg\scripts\buildsystems\vcpkg.cmake"
`
This will compile cleanly and output Successfully installed spz-1.1.0.
Note for maintainers: It would be great to add the set_target_properties fix natively to the CMakeLists.txt to prevent the LNK1149 error on Windows entirely!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions