# Prevent MinGW generator from building "liblib" outputs

**URL:** <https://discourse.cmake.org/t/prevent-mingw-generator-from-building-liblib-outputs/11268>\
**Category:** Code\
**Created:** [July 17, 2024, 2:44am UTC](https://discourse.cmake.org/t/prevent-mingw-generator-from-building-liblib-outputs/11268 "2024-07-17T02:44:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlormand](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/90db22/32.png) [@dlormand](https://discourse.cmake.org/u/dlormand)\
**Post date:** [July 17, 2024, 2:44am UTC](https://discourse.cmake.org/t/prevent-mingw-generator-from-building-liblib-outputs/11268/1 "2024-07-17T02:44:14Z")

</div>

Environment is Windows. I’ve got an existing project that was modified from Makefiles to CMake. It builds a shared DLL library and a binary that uses it. The previous developer had MS Visual C present, and so the default behavior of CMake under Windows was fine. As near as I can tell, it build a “libX.dll” file because “libX” is added as a SHARED library in CMakeLists.txt, and “X.exe” because “X” is added as an executable.

I don’t have Visual C; I prefer MinGW (free, no license), and I can get the project to build with the -G “MinGW Makefiles” generator. However, it appears from looking at the makefiles the generator creates that the default behavior is to prepend “lib” to the shared library target. So it creates a “liblibX.dll” file.

This is undesired behavior. I’d like MinGW to produce the same filenames that Visual C does (even though the internal contents may be somewhat different).

Furthermore, I’d like to preserve the process for Visual C. I’ll bet there’s a way to conditionally switch “add\_executable” and “add\_library” based on a symbol created by the generator. But then I run into another problem, which is I can’t have “X” as the target for both the executable and the library, even though the library is going to end up prepending “lib” and appending “.dll” to the ultimate target.

Is there a way to (conditionally) modify the defaults of the MinGW generator to not prepend “lib” to a shared library?

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [July 17, 2024, 8:49pm UTC](https://discourse.cmake.org/t/prevent-mingw-generator-from-building-liblib-outputs/11268/2 "2024-07-17T20:49:36Z")

</div>

Have a look at [OUTPUT\_NAME](https://cmake.org/cmake/help/latest/prop_tgt/OUTPUT_NAME.html) target property…

---

<div class="post-metadata">

**Author:** ![dlormand](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/90db22/32.png) [@dlormand](https://discourse.cmake.org/u/dlormand)\
**Post date:** [July 18, 2024, 5:30pm UTC](https://discourse.cmake.org/t/prevent-mingw-generator-from-building-liblib-outputs/11268/3 "2024-07-18T17:30:31Z")

</div>

Good, this works. By specifying the OUTPUT\_NAME as a target property, regardless of the build system, I get “libX.dll”.  
Interesting (annoying?) that the generator _still_ prepends “lib” and appends “.dll”. I started out thinking I could specify exactly the filename I wanted, “libX.dll”. But the generator gave me “liblibX.dll.dll”. I have to set the OUTPUT\_NAME to “X” to get “libX.dll”.

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [July 18, 2024, 10:42pm UTC](https://discourse.cmake.org/t/prevent-mingw-generator-from-building-liblib-outputs/11268/4 "2024-07-18T22:42:45Z")

</div>

The `PREFIX` and `SUFFIX` target properties control the `lib` and `.dll` parts respectively. I would advise you not to mess with those though, by default they will be set to follow strong platform/toolchain conventions.

---

<div class="post-metadata">

**Author:** ![Wirtos](https://discourse.cmake.org/user_avatar/discourse.cmake.org/wirtos/32/1081_2.png) [@Wirtos](https://discourse.cmake.org/u/Wirtos)\
**Post date:** [June 29, 2025, 1:38pm UTC](https://discourse.cmake.org/t/prevent-mingw-generator-from-building-liblib-outputs/11268/5 "2025-06-29T13:38:39Z")

</div>

This is still broken with targets named libname.  
If I set my OUTPUT\_NAME “libname” and PREFIX “”, then I get two files generated: libname.dll and liblibname.dll.a.  
CMake 3.31.6 ninja generator

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [July 18, 2025, 8:21pm UTC](https://discourse.cmake.org/t/prevent-mingw-generator-from-building-liblib-outputs/11268/6 "2025-07-18T20:21:39Z")

</div>

> [@Wirtos](#):
>
> liblibname.dll.a.

This (probably) comes from the linker preference for using `-llibname`. Without that, one has to know to manually strip the (extra) `lib` prefix.
