首页 > 解决方案 > 在 CLion 中组装 .asm 文件时出现 CMake 问题

问题描述

我正在尝试在 Clion 上运行 .asm 文件,并且我已经为其安装了 NASM,但是我在指定 ASM 编译器时遇到了问题:

CMake Error at CMakeLists.txt:4 (enable_language):
  The CMAKE_ASM_NASM_COMPILER:

    C:/Users/User/AppData/Local/bin/NASM

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "ASM_NASM" or the CMake cache entry CMAKE_ASM_NASM_COMPILER to the
  full path to the compiler, or to the compiler name if it is in the PATH.


mingw32-make.exe: *** [Makefile:175: cmake_check_build_system] Error 1
-- The ASM_NASM compiler identification is unknown
-- Found assembler: C:/Users/User/AppData/Local/bin/NASM
-- Configuring incomplete, errors occurred!

问题在于这个“完整路径”,但我不太明白它的含义。这是我的 CMakeLists.txt :

cmake_minimum_required(VERSION 3.17)
project(untitled C)
set(CMAKE_ASM_NASM_COMPILER C:/Users/User/AppData/Local/bin/NASM)
enable_language(ASM_NASM)
set(ASM_SOURCES
        test.asm)

set(SOURCES
        ${ASM_SOURCES})

set_source_files_properties(test.asm PROPERTIES LANGUAGE ASM_NASM)

add_executable(program  ${SOURCES})

我在这里也读过类似的问题(但关于 C/C++ 编译器),它们对我的情况并没有真正的帮助。

谢谢你的回答!

标签: windowsassemblycmakenasmclion

解决方案


解决方案(使用Compile ASM 和 C with ASM 进行调试):

cmake_minimum_required(VERSION 3.17)
project(untitled ASM)
enable_language(ASM_NASM)

set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64)
set(CMAKE_ASM_NASM_COMPILE_OBJECT "<CMAKE_ASM_NASM_COMPILER> <INCLUDES> \
    <FLAGS> -f ${CMAKE_ASM_NASM_OBJECT_FORMAT} -o <OBJECT> <SOURCE>")

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(CMAKE_ASM_NASM_FLAGS "${ASM_NASM_FLAGS} -g")
else()
    set(CMAKE_ASM_NASM_FLAGS "${ASM_NASM_FLAGS}")
endif()


set_source_files_properties(test.asm PROPERTIES LANGUAGE ASM_NASM)

add_executable(program  test.asm)

推荐阅读