# Problem with duplicate library names under MS-Windows

**URL:** <https://discourse.cmake.org/t/problem-with-duplicate-library-names-under-ms-windows/5120>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [February 25, 2022, 9:44pm UTC](https://discourse.cmake.org/t/problem-with-duplicate-library-names-under-ms-windows/5120 "2022-02-25T21:44:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SepandMeenu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/sepandmeenu/32/2228_2.png) [@SepandMeenu](https://discourse.cmake.org/u/SepandMeenu)\
**Post date:** [February 25, 2022, 9:44pm UTC](https://discourse.cmake.org/t/problem-with-duplicate-library-names-under-ms-windows/5120/1 "2022-02-25T21:44:09Z")

</div>

Under MS-Windows, if two _different_ shared libraries have the _same_ name, their produced binaries will be the _same_, even if their output directories _differ_.

A minimal example:

```auto
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

project(TestDuplicateNamesMSVC LANGUAGES C)

set(libname prime)
set(libdir1 ${CMAKE_BINARY_DIR}/lib1)
set(libdir2 ${CMAKE_BINARY_DIR}/lib2)

# NOTE: The output names of both libraries are the _same_,
# yet they are built in _different_ directories

# shared library 1
add_library(prime1 SHARED prime1.c)
set_target_properties(prime1 PROPERTIES
    POSITION_INDEPENDENT_CODE ON
    RUNTIME_OUTPUT_NAME ${libname}
    RUNTIME_OUTPUT_DIRECTORY_RELEASE ${libdir1}
    OUTPUT_NAME ${libname}
    LIBRARY_OUTPUT_DIRECTORY ${libdir1}
    )

# shared library 2
add_library(prime2 SHARED prime2.c)
set_target_properties(prime2 PROPERTIES
    POSITION_INDEPENDENT_CODE ON
    RUNTIME_OUTPUT_NAME ${libname}
    RUNTIME_OUTPUT_DIRECTORY_RELEASE ${libdir2}
    OUTPUT_NAME ${libname}
    LIBRARY_OUTPUT_DIRECTORY ${libdir2}
    )

```

- Build

```auto
cmake -B build
cmake --build build --config Release

```

- Compare binaries under MS-Windows

```auto
fc /b .\build\lib1\prime.dll .\build\lib2\prime.dll

```

yields `FC: no differences encountered`.

- Compare binaries under Linux

```auto
diff ./build/lib1/libprime.so ./build/lib2/libprime.so

```

yields `Binary files build/lib1/libprime.so and build/lib2/libprime.so differ`.

Tested with MSVC 19.29 under Windows 10 and GCC 10.2 under Linux, both with x64 architecture.

---

<div class="post-metadata">

**Author:** ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)\
**Post date:** [February 25, 2022, 10:33pm UTC](https://discourse.cmake.org/t/problem-with-duplicate-library-names-under-ms-windows/5120/2 "2022-02-25T22:33:47Z")

</div>

What about the `.lib` files? Are they identical?

Do these libraries actually export symbols? If they don’t, then the `.dll` files are basically empty shells, so it would make sense that they are identical.

---

<div class="post-metadata">

**Author:** ![SepandMeenu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/sepandmeenu/32/2228_2.png) [@SepandMeenu](https://discourse.cmake.org/u/SepandMeenu)\
**Post date:** [February 26, 2022, 1:24pm UTC](https://discourse.cmake.org/t/problem-with-duplicate-library-names-under-ms-windows/5120/3 "2022-02-26T13:24:00Z")

</div>

Thank you for the reply. The problem was that I had forgotten to export the symbols in the source files; that is, `__declspec(dllexport)` was not added.
