# Building Lib file from asm - cmake bug?

**URL:** <https://discourse.cmake.org/t/building-lib-file-from-asm-cmake-bug/1959>\
**Category:** Code\
**Tags:** comp:msvc, gen:makefiles, os:windows\
**Created:** [October 2, 2020, 9:56am UTC](https://discourse.cmake.org/t/building-lib-file-from-asm-cmake-bug/1959 "2020-10-02T09:56:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anrose00](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@anrose00](https://discourse.cmake.org/u/anrose00)\
**Post date:** [October 2, 2020, 9:56am UTC](https://discourse.cmake.org/t/building-lib-file-from-asm-cmake-bug/1959/1 "2020-10-02T09:56:56Z")

</div>

Hello!

I’m trying to convert a larger project to cmake. It consists or various C and ASM files.  
I was trying to create a static library containing the functions provided by the ASM files and then linking this static lib with the C files. But I ran into a strange error:

> Microsoft (R) Library Manager Version 14.16.27043.0  
> Copyright (C) Microsoft Corporation. All rights reserved.
> 
> LINK : fatal error LNK1181: cannot open input file ‘cr’

OS: Win10, Build tools: VS 2017, Generator: NMAKE, platform: x64. Cmake version: 3.18.2

I tried this with a minimal example and got the same error:

```
cmake_minimum_required(VERSION 3.10)
# set the project name
project(LibTest)
enable_language(ASM_MASM)
set(SOURCES_ASM test.asm)
set_source_files_properties(${SOURCES_ASM} PROPERTY LANGUAGE ASM_MASM)
ADD_LIBRARY(LibAsm STATIC ${SOURCES_ASM})

```

When examining the “build.make” file being generated, I found this:

C:\PROGRA~2.…\Hostx64\x64\lib.exe _ **cr** _ LibAsm.lib /machine:x64 $(LibAsm\_OBJECTS) $(LibAsm\_EXTERNAL\_OBJECTS)

Is there a problem with my Cmake file? Is this a bug? Any hints, how to avoid that?

Any help is appreciated. Thanks

EDIT:

- with ninja generator the same error of the lib tool appears
- a similar small example with a C file works fine

---

<div class="post-metadata">

**Author:** ![anrose00](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@anrose00](https://discourse.cmake.org/u/anrose00)\
**Post date:** [October 2, 2020, 11:32am UTC](https://discourse.cmake.org/t/building-lib-file-from-asm-cmake-bug/1959/2 "2020-10-02T11:32:58Z")

</div>

After some research it seems, it is actually a bug in cmake:

[https://gitlab.kitware.com/cmake/cmake/-/issues/18889](https://gitlab.kitware.com/cmake/cmake/-/issues/18889)

> **[CMake+Ninja - Developer Community](https://developercommunity.visualstudio.com/content/problem/420340/cmakeninja.html)**

Adding this to the project file causes the error to disappear:

```
set(CMAKE_ASM_MASM_CREATE_STATIC_LIBRARY "<CMAKE_AR> /OUT:<TARGET> <LINK_FLAGS> <OBJECTS>")
```

---

<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:** [November 24, 2020, 11:51pm UTC](https://discourse.cmake.org/t/building-lib-file-from-asm-cmake-bug/1959/3 "2020-11-24T23:51:15Z")

</div>

@brad.king Seems like an `env-regression`?

---

<div class="post-metadata">

**Author:** ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)\
**Post date:** [November 25, 2020, 12:03pm UTC](https://discourse.cmake.org/t/building-lib-file-from-asm-cmake-bug/1959/4 "2020-11-25T12:03:39Z")

</div>

I’ve already responded in the corresponding issue to suggest a path forward.
