我尝试在Visual Studio中使用cmake编译asm。我有main.cpp,JustValue.asm.我的CmakeList.txt看起来像这样:
cmake_minimum_required(VERSION 3.14)
project(
asm_test
LANGUAGES CXX
)
enable_language(C ASM)
add_executable(${PROJECT_NAME} main.cpp JustValue.asm)
set_target_properties(
${PROJECT_NAME} PROPERTIES
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON
)
main.cpp:
#include <iostream>
extern "C" int JustValue();
int main() {
std::cout << "Value = " << JustValue() << std::endl;
}
asm文件:
.code
JustValue proc
mov eax, 7
ret
JustValue endp
end
和链接器生成错误
>------ Build started: Project: CMakeLists, Configuration: Debug ------
[1/3] Building ASM object CMakeFiles\asm_test.dir\JustValue.asm.obj
Microsoft (R) C/C++ Optimizing Compiler Version 19.32.31332 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Users\ruden\source\repos\asm_test\out\build\x64-Debug\cl : Command line warning D9035: option 'o' has been deprecated and will be removed in a future release
C:\Users\ruden\source\repos\asm_test\out\build\x64-Debug\cl : Command line warning D9024: unrecognized source file type 'C:\Users\ruden\source\repos\asm_test\JustValue.asm', object file assumed
C:\Users\ruden\source\repos\asm_test\out\build\x64-Debug\cl : Command line warning D9027: source file 'C:\Users\ruden\source\repos\asm_test\JustValue.asm' ignored
C:\Users\ruden\source\repos\asm_test\out\build\x64-Debug\cl : Command line warning D9021: no action performed
[2/3] Building CXX object CMakeFiles\asm_test.dir\main.cpp.obj
[3/3] Linking CXX executable asm_test.exe
FAILED: asm_test.exe
cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\asm_test.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\mt.exe --manifests -- C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1432~1.313\bin\Hostx64\x64\link.exe /nologo CMakeFiles\asm_test.dir\main.cpp.obj CMakeFiles\asm_test.dir\JustValue.asm.obj /out:asm_test.exe /implib:asm_test.lib /pdb:asm_test.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK Pass 1: command "C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1432~1.313\bin\Hostx64\x64\link.exe /nologo CMakeFiles\asm_test.dir\main.cpp.obj CMakeFiles\asm_test.dir\JustValue.asm.obj /out:asm_test.exe /implib:asm_test.lib /pdb:asm_test.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\asm_test.dir/intermediate.manifest CMakeFiles\asm_test.dir/manifest.res" failed (exit code 1104) with the following output:
C:\Users\ruden\source\repos\asm_test\out\build\x64-Debug\LINK : fatal error LNK1104: cannot open file 'CMakeFiles\asm_test.dir\JustValue.asm.obj'
ninja: build stopped: subcommand failed.
我应该怎么做来修复这个错误?
1条答案
按热度按时间zzwlnbp81#
我只需要一条线!我用enable_language(C ASM)替换了enable_language(C ASM)
谢谢https://gitlab.kitware.com/cmake/cmake/-/issues/21462