# building a shared library NMAKE : fatal error U1077

**URL:** https://discourse.cmake.org/t/building-a-shared-library-nmake-fatal-error-u1077/7854
**Category:** Usage
**Tags:** os:windows, comp:msvc, gen:makefiles
**Created:** [April 7, 2023, 11:07am UTC](https://discourse.cmake.org/t/building-a-shared-library-nmake-fatal-error-u1077/7854 "2023-04-07T11:07:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [April 7, 2023, 11:07am UTC](https://discourse.cmake.org/t/building-a-shared-library-nmake-fatal-error-u1077/7854/1 "2023-04-07T11:07:41Z")

</div>

Hi,

I’m trying to build a simple shared library example.  
With the included project, I’ve got an error on build:

```auto
"C:\Program Files\CMake\bin\cmake.exe" -E __create_def CMakeFiles\TestShared.dir\exports.def CMakeFiles\TestShared.dir\exports.def.objs
NMAKE : fatal error U1077: '"C:\Program Files\CMake\bin\cmake.exe"' : code '0xc0000005'

```

The equivalent project for mingw/gcc compiles and can be used by an application.

How do I fix my CMakeLists?  
Thanks in advance, regards,  
A.  
[CMakeExample.7z](https://discourse.cmake.org/uploads/short-url/cvOT8EjbbTm3LPBTEIjg0ZsUQBY.7z) (2.2 KB)

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [April 7, 2023, 3:28pm UTC](https://discourse.cmake.org/t/building-a-shared-library-nmake-fatal-error-u1077/7854/2 "2023-04-07T15:28:31Z")

</div>

First of all, a /LD was missing but now I’ve got another issue.

The shared library is compiled and seemed to be properly install but the client application cannot link:

```auto
TestExe.cpp.obj : error LNK2001: unresolved external symbol "int __cdecl TestSharedFcn(void)"

```

I’m joining a more complete example.

[CMakeExample.7z](https://discourse.cmake.org/uploads/short-url/fP95gz9cJRBcrBHRokEXpsmpSAF.7z) (2.4 KB)

PS I suspect that there is an issue with the linkage to the associated import library.

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [April 10, 2023, 1:15pm UTC](https://discourse.cmake.org/t/building-a-shared-library-nmake-fatal-error-u1077/7854/3 "2023-04-10T13:15:53Z")

</div>

Strangely enough: if I build a second time the error disappears.  
I’m still failing to understand why.

Help would be appreciated on the proper way to build a msvc shared library  
A.

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [April 10, 2023, 1:49pm UTC](https://discourse.cmake.org/t/building-a-shared-library-nmake-fatal-error-u1077/7854/4 "2023-04-10T13:49:29Z")

</div>

The issues seems to be related to [https://gitlab.kitware.com/cmake/cmake/-/issues/16282](https://gitlab.kitware.com/cmake/cmake/-/issues/16282)  
Removing `CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS` usage and using GenerateExportHeader solves the issue in my case.

A.
