Skip to content

Build Windows import libraries with the linker's own lib - #131

Merged
ethindp merged 1 commit into
ethindp:masterfrom
trypsynth:fix/x86-import-library-tool
Sep 22, 2026
Merged

ethindp merged 1 commit into
ethindp:masterfrom
trypsynth:fix/x86-import-library-tool

Conversation

@trypsynth

Copy link
Copy Markdown
Contributor

On x86, the import libraries for ZDSR, BoyPCReader and PC-Talker come out with the wrong symbol names whenever llvm-lib is on PATH, and prism fails to link:

boy_pc_reader.obj : error LNK2001: unresolved external symbol __imp__BoyCtrlSpeak@12
pc_talker.obj : error LNK2001: unresolved external symbol __imp__PCTKStatus@0
prism.dll : fatal error LNK1120: 18 unresolved externals

find_program(PRISM_LIB_TOOL NAMES lib llvm-lib) searches PATH, and MSVC's lib is only on PATH inside a developer prompt. Outside one, a Visual Studio generator build picks up llvm-lib wherever LLVM is installed, which includes GitHub's Windows runners. The two read the *32.def files differently. Given PCTKStatus@0, lib makes the symbol _PCTKStatus@0 and imports PCTKStatus@0, while llvm-lib makes the symbol PCTKStatus@0 as written. The compiler asks for the underscored name, so only lib's output links. On x64 and ARM64 nothing is decorated, so the two tools agree there and the problem stays hidden.

What this does

The search now looks beside CMAKE_LINKER first. With MSVC that is where lib.exe lives, so the librarian always matches the toolchain doing the build. With clang-cl and lld-link, the linker's directory is LLVM's own, so llvm-lib is still what it finds. PATH is searched afterwards, as before.

Testing

Built shared for Win32 with the Visual Studio 2022 generator, with Scoop's LLVM first on PATH. Before, the link failed as above. After, PRISM_LIB_TOOL resolves to MSVC's Hostx64/x86/lib.exe, prism links, and dumpbin /imports shows PCTKUSR.dll imported by the names the definition files give, such as PCTKPinStatus@0. Not tested with clang-cl.

@ethindp
ethindp merged commit 43fa631 into ethindp:master Sep 22, 2026
65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants