Skip to content

Commit 9931c0f

Browse files
committed
Small hotfix for venvs
1 parent bc3c1ee commit 9931c0f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

hatch_cpp/toolchains/common.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pathlib import Path
55
from re import match
66
from shutil import which
7-
from sys import executable, platform as sys_platform
7+
from sys import base_exec_prefix, exec_prefix, platform as sys_platform
88
from sysconfig import get_path
99
from typing import Any, List, Literal, Optional
1010

@@ -230,8 +230,13 @@ def get_link_flags(self, library: HatchCppLibrary, build_type: BuildType = "rele
230230
flags += " /LD"
231231
flags += f" /Fe:{library.get_qualified_name(self.platform)}"
232232
flags += " /link /DLL"
233-
if (Path(executable).parent / "libs").exists():
234-
flags += f" /LIBPATH:{str(Path(executable).parent / 'libs')}"
233+
# Add Python library directories, mirroring CPython's distutils behavior.
234+
# In virtual environments, sys.executable is in the venv, but pythonXX.lib
235+
# lives under the base Python installation's 'libs' directory.
236+
for prefix in dict.fromkeys((exec_prefix, base_exec_prefix)):
237+
libs_dir = Path(prefix) / "libs"
238+
if libs_dir.exists():
239+
flags += f" /LIBPATH:{libs_dir}"
235240
flags += " " + " ".join(f"{lib}.lib" for lib in library.libraries)
236241
flags += " " + " ".join(f"/LIBPATH:{lib}" for lib in library.library_dirs)
237242
# clean

0 commit comments

Comments
 (0)