![](/img/trans.png)
[英]How to change cmake build directory in `cmake-kits.json` or `cmake-variants.json` of vscode
[英]How to change build machine type with CMake
我正在學習如何使用 CMake,
我正在將一個工作項目從 Visual Studio 轉換為 Cmake 並使用 NMake 構建。 當前項目為 x64 和 x86 構建。 我的操作系統是 windows 10
我當前的 CMakeLists.txt 非常簡單:
cmake_minimum_required(VERSION 3.13.0)
project(example CXX)
ADD_DEFINITIONS(-DUNICODE)
ADD_DEFINITIONS(-D_UNICODE)
set(CMAKE_CXX_FLAGS -G"NMake Makefiles")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(SimManager
Source/main.cpp
)
set_target_properties (${PROJECT_NAME} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED TRUE
CXX_EXTENSIONS FALSE
)
我用來構建的命令是: cmake -G"NMake Makefiles..
nmake
我得到的錯誤是
fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86'
我了解 NMake 選擇使用哪個編譯器 x86 或 x64 的方式是打開相應的控制台終端。 我正在為 VS 2017 使用 Select x64 Native Tools 命令提示符
執行的 linker 的命令行是:
command "C:\PROGRA~2\MIB055~1\2019\ENTERP~1\VC\Tools\MSVC\1425~1.286\bin\Hostx86\x86\link.exe /nologo @CMakeFiles\example.dir\objects1.rsp /out:SimManager.exe /implib:SimManager.lib /pdb:E:\Projects\example\Debug\example.pdb /version:0.0 /machine:X86 /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\example.dir/intermediate.manifest CMakeFiles\example.dir/manifest.res" failed (exit code 1112) with the following output: fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86'
我可以看到它設置了 /machine:X86 。 我沒有在 CMakeLists.txt 中設置它。 如何讓它使用 64 位 linker?
我嘗試將建議的 arguments 添加到 cmake 調用中,但沒有任何區別
cmake -G"NMake Makefiles" --build build64 --config Release -host_arch=amd64 -arch=amd64..
還嘗試添加到 CMakeLists,同樣的錯誤仍然存在
set(CMAKE_SYSTEM_PROCESSOR AMD64)
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-m64" LINK_FLAGS "-m64")
set(ARCH amd64)
如果可能的話,我寧願在 CMakeLists.txt 中進行更改,這樣我就可以盡可能地顯示命令行調用。 這個項目不是為 32 位構建的。
謝謝
嘗試在CMakeLists.txt
中添加以下內容:
target_link_options(target PRIVATE /machine:x64)
請參閱文檔。
或者您可以編輯CMakeCache.txt
並更改以下變量:
CMAKE_MODULE_LINKER_FLAGS:STRING=/machine:x64
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.