# How to add library with only module interface unit in msvc?

**URL:** https://discourse.cmake.org/t/how-to-add-library-with-only-module-interface-unit-in-msvc/14355
**Category:** Usage
**Created:** [July 14, 2025, 12:46pm UTC](https://discourse.cmake.org/t/how-to-add-library-with-only-module-interface-unit-in-msvc/14355 "2025-07-14T12:46:33Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![paperchalice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/paperchalice/32/5205_2.png) [@paperchalice](https://discourse.cmake.org/u/paperchalice)
#### Post date: [July 14, 2025, 12:46pm UTC](https://discourse.cmake.org/t/how-to-add-library-with-only-module-interface-unit-in-msvc/14355/1 "2025-07-14T12:46:34Z")

</div>

Show case:

```c++
// test.ixx
export module foo;
// No member is declared with dllexport, this is the simplest case.

```

```c++
// test.cpp
import foo;
int main() {}

```

CMakeLists.txt:

```cmake
cmake_minimum_required(VERSION 4.1)

project(test)

set(BUILD_SHARED_LIBS ON)
set(CMAKE_CXX_STANDARD 23)

add_library(test)
add_executable(t
    test.cpp
)
target_sources(test
    INTERFACE
        FILE_SET CXX_MODULES
        FILES
            test.ixx
)
target_link_libraries(t
    PRIVATE
        test
)

```

Apparently there is no `test.lib` generated because target `test` doesn’t export any symbol, and result in “LNK1104 cannot open file `Debug\test.lib`”. As a workaround I must set `CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS` to ON.  
In header files time, I can add it as an interface library, but interface library doesn’t support modules…  
So what is the solution for this problem? Thanks!

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [July 14, 2025, 1:08pm UTC](https://discourse.cmake.org/t/how-to-add-library-with-only-module-interface-unit-in-msvc/14355/2 "2025-07-14T13:08:07Z")

</div>

It kinda looks like what you want is an `INTERFACE` library…

---

<div class="post-metadata">

### Author: ![paperchalice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/paperchalice/32/5205_2.png) [@paperchalice](https://discourse.cmake.org/u/paperchalice)
#### Post date: [July 14, 2025, 1:33pm UTC](https://discourse.cmake.org/t/how-to-add-library-with-only-module-interface-unit-in-msvc/14355/3 "2025-07-14T13:33:57Z")

</div>

Yeah, unfortunately interface library doesn’t support module.😢
