Building Lib file from asm - cmake bug?


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 ® Library Manager Version 14.16.27043.0
Copyright © 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
set(SOURCES_ASM test.asm)
set_source_files_properties(${SOURCES_ASM} PROPERTY LANGUAGE ASM_MASM)

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


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

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

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


@brad.king Seems like an env-regression?

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