Linker error with CXX_MODULES

I have a project that build Boost with CXX_MODULES. It works on Linux and OSX, but not on windows?

The type_index lib is a header only module the any lib too. The any module itself imports the type_index.

[367/557] Linking CXX shared library bin\boost_type_index-vc143-mt-x64-1_90.dll
[368/557] Generating CXX dyndep file examples\CMakeFiles\ExampleAny.dir\CXX.dd
[369/557] Generating CXX dyndep file examples\CMakeFiles\ExampleRegex.dir\CXX.dd
[370/557] Generating CXX dyndep file examples\CMakeFiles\ExampleAsio.dir\CXX.dd
[371/557] Generating CXX dyndep file examples\CMakeFiles\ExampleTest.dir\CXX.dd
[372/557] Linking CXX shared library bin\boost_any-vc143-mt-x64-1_90.dll
FAILED: [code=4294967295] bin/boost_any-vc143-mt-x64-1_90.dll lib/boost_any-vc143-mt-x64-1_90.lib 
C:\Windows\system32\cmd.exe /C "cd . && D:\a\_temp\1869045051\cmake-4.2.1-windows-x86_64\bin\cmake.exe -E vs_link_dll --msvc-ver=1944 --intdir=_deps\boost-build\libs\any\CMakeFiles\boost_any.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\link.exe /nologo _deps\boost-build\libs\any\CMakeFiles\boost_any.dir\modules\boost_any.cppm.obj  /out:bin\boost_any-vc143-mt-x64-1_90.dll /implib:lib\boost_any-vc143-mt-x64-1_90.lib /pdb:bin\boost_any-vc143-mt-x64-1_90.pdb /dll /version:1.90 -machine:x64 /INCREMENTAL:NO  lib\boost_type_index-vc143-mt-x64-1_90.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command "C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\link.exe /nologo _deps\boost-build\libs\any\CMakeFiles\boost_any.dir\modules\boost_any.cppm.obj /out:bin\boost_any-vc143-mt-x64-1_90.dll /implib:lib\boost_any-vc143-mt-x64-1_90.lib /pdb:bin\boost_any-vc143-mt-x64-1_90.pdb /dll /version:1.90 -machine:x64 /INCREMENTAL:NO lib\boost_type_index-vc143-mt-x64-1_90.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST:EMBED,ID=2" failed (exit code 1181) with the following output:
LINK : fatal error LNK1181: cannot open input file 'lib\boost_type_index-vc143-mt-x64-1_90.lib'

The code is here: Bump version: 1.90.0-dev1 by ClausKlein · Pull Request #11 · ClausKlein/boost-cmake · GitHub

Try -DBOOST_ALL_NO_LIB? Though the library is directly on the command line, so autolinking is unlikely the direct cause…

Oh…this is building Boost itself! The lack of a .lib usually means that the DLL is not exporting any symbols from it. The linker only makes a .lib if the DLL exports symbols.

Both libs are header only build as CXX_MODULES

bash-5.3$ dyld_info libboost_type_index.1.90.0.dylib
libboost_type_index.1.90.0.dylib [x86_64]:
    -platform:
        platform     minOS      sdk
           macOS     14.0      14.0   
    -segments:
        load-offset   segment section        sect-size  seg-size perm
        0x00000000    __TEXT                                 8KB r.x
        0x00001F10             __text               70
        0x00001F56             __stubs              12
        0x00001F62             __const              57
        0x00001F9C             __unwind_info        96
        0x00002000    __DATA_CONST                           4KB rw.
        0x00002000             __got                16
        0x00002010             __const              64
    -dependents:
        attributes     load path
                       /usr/local/opt/llvm/lib/c++/libc++abi.1.dylib
                       /usr/local/opt/llvm/lib/c++/libc++.1.dylib
                       /usr/lib/libSystem.B.dylib
bash-5.3$ dyld_info libboost_any.1.90.0.dylib
libboost_any.1.90.0.dylib [x86_64]:
    -platform:
        platform     minOS      sdk
           macOS     14.0      14.0   
    -segments:
        load-offset   segment section        sect-size  seg-size perm
        0x00000000    __TEXT                                 8KB r.x
        0x00001BD0             __text              768
        0x00001ED0             __stubs              12
        0x00001EDC             __cstring            61
        0x00001F19             __const             119
        0x00001F90             __unwind_info       112
        0x00002000    __DATA_CONST                           4KB rw.
        0x00002000             __got                24
        0x00002018             __const             192
    -dependents:
        attributes     load path
                       /usr/local/opt/llvm/lib/c++/libc++abi.1.dylib
                       /usr/local/opt/llvm/lib/c++/libc++.1.dylib
                       @rpath/libboost_type_index.1.90.0.dylib
                       /usr/lib/libSystem.B.dylib
bash-5.3$ dyld_info libboost_a.1.90.0.dylib
libboost_any.1.90.0.dylib     libboost_any.dylib            libboost_atomic.1.90.0.dylib  libboost_atomic.dylib         
bash-5.3$ dyld_info libboost_atomic.1.90.0.dylib
libboost_atomic.1.90.0.dylib [x86_64]:
    -platform:
        platform     minOS      sdk
           macOS     14.0      14.0   
    -segments:
        load-offset   segment section        sect-size  seg-size perm
        0x00000000    __TEXT                                12KB r.x
        0x00002010             __text             3370
        0x00002D3A             __stubs             126
        0x00002DB8             __gcc_except_tab    284
        0x00002ED4             __unwind_info       296
        0x00003000    __DATA_CONST                           4KB rw.
        0x00003000             __got               184
        0x00004000    __DATA                                36KB rw.
        0x00004000             __data            32776
        0x0000C008             __bss                 1
    -dependents:
        attributes     load path
                       /usr/local/opt/llvm/lib/c++/libc++abi.1.dylib
                       /usr/local/opt/llvm/lib/c++/libc++.1.dylib
                       /usr/lib/libSystem.B.dylib
bash-5.3$ 

see too Header-only libraries and C++20 modules

and type_index/modules/boost_type_index.cppm at develop · boostorg/type_index · GitHub

If I build static libs on Windows, it works:

Modules provide a “module initialization symbol” that imports call. This is how modules are able to order global static initializations.

There’s been talk of an attribute one can use (export module x [[module_noinit]]; or something) to say "this module pinky swears to need no global static initialization (even transitively). which would allow importers to skip calling it. It hasn’t gone anywhere yet (not even a paper).

Until then, all named module providers must provide some kind of library artifact to provide such symbols.