Skip to content

Commit f1ba959

Browse files
author
Dreams-Makers Studio
committed
fix(windows): MSVC whole-archive linking for CLI and test_rle2
MSVC's linker only pulls .obj files from static libraries when symbols are directly referenced through the dependency chain. The CLI and test_rle2 use internal library symbols (extern globals, internal functions) not reachable from the public API, so MSVC silently skips those .obj files. Fix: /WHOLEARCHIVE:maxcomp forces MSVC to include all object files from the static library.
1 parent f461ebe commit f1ba959

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

cli/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# ─── MaxCompression CLI ──────────────────────────────────────────────
22

33
add_executable(mcx main.c)
4+
if(MSVC)
5+
# CLI uses internal library symbols (extern globals, internal functions)
6+
# MSVC only pulls referenced .obj from static libs, so force whole-archive.
7+
target_link_options(mcx PRIVATE /WHOLEARCHIVE:maxcomp)
8+
endif()
49
target_link_libraries(mcx PRIVATE maxcomp_static)
510
# Pass library feature flags for `mcx version --build` display
611
target_compile_definitions(mcx PRIVATE MCX_USE_DIVSUFSORT=1)

tests/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ add_test(NAME comprehensive COMMAND test_comprehensive)
3737

3838
# RLE2 (RUNA/RUNB) encoder/decoder tests
3939
add_executable(test_rle2 test_rle2.c)
40+
if(MSVC)
41+
# MSVC linker only pulls referenced .obj from static libs; test_rle2 uses
42+
# internal symbols not reachable from the public API, so we need /WHOLEARCHIVE.
43+
target_link_options(test_rle2 PRIVATE /WHOLEARCHIVE:maxcomp)
44+
endif()
4045
target_link_libraries(test_rle2 PRIVATE maxcomp_static)
4146
if(UNIX)
4247
target_link_libraries(test_rle2 PRIVATE m)

0 commit comments

Comments
 (0)