# C++20 Modules MSVC error C7621: module partition 'Order' for module unit 'Mod2' was not found

**URL:** <https://discourse.cmake.org/t/c-20-modules-msvc-error-c7621-module-partition-order-for-module-unit-mod2-was-not-found/8177>\
**Category:** Development\
**Tags:** os:windows\
**Created:** [May 22, 2023, 8:02am UTC](https://discourse.cmake.org/t/c-20-modules-msvc-error-c7621-module-partition-order-for-module-unit-mod2-was-not-found/8177 "2023-05-22T08:02:54Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [May 22, 2023, 8:02am UTC](https://discourse.cmake.org/t/c-20-modules-msvc-error-c7621-module-partition-order-for-module-unit-mod2-was-not-found/8177/1 "2023-05-22T08:02:54Z")

</div>

### With this snipped, the example works with `clang++-16`, but not with **MSVC**?

```cmake
#
# module with one internal partition
# see too:
# https://learn.microsoft.com/en-us/cpp/build/reference/internal-partition?view=msvc-170
#
add_library(mod2)
target_sources(
  mod2
  PRIVATE mod2/mod2price.cpp
  PUBLIC FILE_SET
         cxx_modules
         TYPE
         CXX_MODULES
         FILES
         mod2/mod2.cppm
         mod2/mod2order.cppm # internal partition
)
set_target_properties(mod2 PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD})
if(CMAKE_SKIP_INSTALL_RULES AND CMAKE_BUILD_TYPE STREQUAL "Debug")
  target_link_libraries(mod2 PUBLIC $<BUILD_INTERFACE:project_warnings project_options>)
endif()
add_executable(testmod2 mod2/testmod2.cpp)
target_link_libraries(testmod2 mod2)
add_test(NAME testmod2 COMMAND testmod2)

```

The log and the code can be found here: [https://github.com/ClausKlein/cppstd20-code/actions/runs/5042138569/jobs/9042469820#step:5:170](https://github.com/ClausKlein/cppstd20-code/actions/runs/5042138569/jobs/9042469820#step:5:170)

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [May 22, 2023, 3:47pm UTC](https://discourse.cmake.org/t/c-20-modules-msvc-error-c7621-module-partition-order-for-module-unit-mod2-was-not-found/8177/2 "2023-05-22T15:47:59Z")

</div>

@ben.boeckel is this a usage error or an `CMake` generator error?

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [May 23, 2023, 7:22am UTC](https://discourse.cmake.org/t/c-20-modules-msvc-error-c7621-module-partition-order-for-module-unit-mod2-was-not-found/8177/3 "2023-05-23T07:22:52Z")

</div>

@bill.hoffman Is there a portable way to work with partitions?

I tried also this branch [Commits · mathstuf/cxx-modules-sandbox · GitHub](https://github.com/mathstuf/cxx-modules-sandbox/commits/new-builds) without success.

---

<div class="post-metadata">

**Author:** ![bill.hoffman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bill.hoffman/32/13_2.png) [@bill.hoffman](https://discourse.cmake.org/u/bill.hoffman)\
**Post date:** [May 23, 2023, 2:32pm UTC](https://discourse.cmake.org/t/c-20-modules-msvc-error-c7621-module-partition-order-for-module-unit-mod2-was-not-found/8177/4 "2023-05-23T14:32:24Z")

</div>

Are you using the VS generator? This was recently fixed in VS and CMake.  
[https://gitlab.kitware.com/cmake/cmake/-/merge\_requests/8471](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/8471)  
So, you need a new version of CMake ad VS.

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [May 23, 2023, 3:57pm UTC](https://discourse.cmake.org/t/c-20-modules-msvc-error-c7621-module-partition-order-for-module-unit-mod2-was-not-found/8177/5 "2023-05-23T15:57:03Z")

</div>

With `WindowsToolchain` and current `ninja` it works for static libs. 🙂

Only `shared libs` still makes trouble: [Build all modules with cmake and clang-16 on OSX · ClausKlein/cppstd20-code@58d6611 · GitHub](https://github.com/ClausKlein/cppstd20-code/actions/runs/5059295835/jobs/9080615962#step:5:12) 🤔

---

<div class="post-metadata">

**Author:** ![bill.hoffman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bill.hoffman/32/13_2.png) [@bill.hoffman](https://discourse.cmake.org/u/bill.hoffman)\
**Post date:** [May 23, 2023, 5:12pm UTC](https://discourse.cmake.org/t/c-20-modules-msvc-error-c7621-module-partition-order-for-module-unit-mod2-was-not-found/8177/6 "2023-05-23T17:12:18Z")

</div>

You still need to dll export symbols from the shared library. See the following links for ways to do that:  
[https://www.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/](https://www.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/).  
[https://cmake.org/cmake/help/latest/module/GenerateExportHeader.html](https://cmake.org/cmake/help/latest/module/GenerateExportHeader.html)  
[https://cmake.org/cmake/help/latest/prop\_tgt/WINDOWS\_EXPORT\_ALL\_SYMBOLS.html](https://cmake.org/cmake/help/latest/prop_tgt/WINDOWS_EXPORT_ALL_SYMBOLS.html)

For a tested example see:  
[https://gitlab.kitware.com/cmake/cmake/-/tree/master/Tests/RunCMake/CXXModules/examples/library](https://gitlab.kitware.com/cmake/cmake/-/tree/master/Tests/RunCMake/CXXModules/examples/library)

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [May 23, 2023, 7:49pm UTC](https://discourse.cmake.org/t/c-20-modules-msvc-error-c7621-module-partition-order-for-module-unit-mod2-was-not-found/8177/7 "2023-05-23T19:49:54Z")

</div>

This seems an other problem.

```auto
[5/359] Linking CXX shared library bin\mod0D.dll
...
[7/359] Scanning D:\a\cppstd20-code\cppstd20-code\modules\mod0main.cpp for CXX dependencies
[8/359] Generating CXX dyndep file modules\CMakeFiles\mod0main.dir\CXX.dd
...
[14/359] Building CXX object modules\CMakeFiles\mod0main.dir\mod0main.cpp.obj
[15/359] Linking CXX executable bin\mod0main.exe
FAILED: bin/mod0main.exe

cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=modules\CMakeFiles\mod0main.dir
--rc=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\mt.exe --manifests
-- C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1435~1.322\bin\Hostx64\x64\link.exe /nologo
modules\CMakeFiles\mod0main.dir\mod0main.cpp.obj /out:bin\mod0main.exe /implib:modules\mod0main.lib /pdb:bin\mod0main.pdb
/version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console
-LIBPATH:C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1435~1.322\ATLMFC\lib\x64
-LIBPATH:C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1435~1.322\lib\x64
-LIBPATH:C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1435~1.322\lib\x86\store\REFERE~1
-LIBPATH:C:\PROGRA~2\WI3CF2~1\10\lib\100226~1.0\ucrt\x64 -LIBPATH:C:\PROGRA~2\WI3CF2~1\10\lib\100226~1.0\um\x64
-LIBPATH:"C:\Program Files (x86)\Windows Kits\10\References\x64" modules\mod0D.lib kernel32.lib user32.lib gdi32.lib
winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."

LINK Pass 1: command "C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1435~1.322\bin\Hostx64\x64\link.exe /nologo
modules\CMakeFiles\mod0main.dir\mod0main.cpp.obj /out:bin\mod0main.exe /implib:modules\mod0main.lib /pdb:bin\mod0main.pdb
/version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console
-LIBPATH:C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1435~1.322\ATLMFC\lib\x64
-LIBPATH:C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1435~1.322\lib\x64
-LIBPATH:C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1435~1.322\lib\x86\store\REFERE~1
-LIBPATH:C:\PROGRA~2\WI3CF2~1\10\lib\100226~1.0\ucrt\x64 -LIBPATH:C:\PROGRA~2\WI3CF2~1\10\lib\100226~1.0\um\x64
-LIBPATH:C:\Program Files (x86)\Windows Kits\10\References\x64 modules\mod0D.lib kernel32.lib user32.lib gdi32.lib
winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST
/MANIFESTFILE:modules\CMakeFiles\mod0main.dir/intermediate.manifest modules\CMakeFiles\mod0main.dir/manifest.res" failed
(exit code 1104) with the following output:

LINK : fatal error LNK1104: cannot open file 'modules\mod0D.lib'

```

---

<div class="post-metadata">

**Author:** ![bill.hoffman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bill.hoffman/32/13_2.png) [@bill.hoffman](https://discourse.cmake.org/u/bill.hoffman)\
**Post date:** [May 23, 2023, 8:48pm UTC](https://discourse.cmake.org/t/c-20-modules-msvc-error-c7621-module-partition-order-for-module-unit-mod2-was-not-found/8177/8 "2023-05-23T20:48:19Z")

</div>

> [@ClausKlein](#):
>
> ` bin\mod0D.dll`

Looks like that problem to me. It is creating the .dll and that dll does not have a .lib file that happens when no symbols are exported. Are you doing anything to export symbols in your code?

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [May 23, 2023, 8:50pm UTC](https://discourse.cmake.org/t/c-20-modules-msvc-error-c7621-module-partition-order-for-module-unit-mod2-was-not-found/8177/9 "2023-05-23T20:50:38Z")

</div>

OK, I have no export → no lib; I have to fix it. Thanks

---

<div class="post-metadata">

**Author:** ![bill.hoffman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bill.hoffman/32/13_2.png) [@bill.hoffman](https://discourse.cmake.org/u/bill.hoffman)\
**Post date:** [May 23, 2023, 9:38pm UTC](https://discourse.cmake.org/t/c-20-modules-msvc-error-c7621-module-partition-order-for-module-unit-mod2-was-not-found/8177/10 "2023-05-23T21:38:47Z")

</div>

Welcome to windows dlls. 🙂
