Sim*_*mon 6 architecture windows cmake clang ninja
我想在我的 x64 Windows 计算机上构建 x86 Windows 应用程序。
\n\n我使用 CMake、Ninja、clang-cl、lld-link 和 VS Build Tools 2017 以及以下 CMakeLists
\n\ncmake_minimum_required(VERSION 3.9)\nproject(Test CXX)\n\nadd_library(TestLib STATIC "")\ntarget_include_directories(TestLib\n PUBLIC\nTestLib/inc\n)\ntarget_sources(TestLib\n PRIVATE\n TestLib/src/Flop.cpp\n TestLib/src/testClass.cpp\n)\n\nadd_executable(Test "")\ntarget_sources(Test\n PRIVATE\n src/main.cpp\n)\ntarget_link_libraries(Test\n TestLib\n)\nRun Code Online (Sandbox Code Playgroud)\n\n我的设置适用于 x64 应用程序。我初始化构建环境并vcvars64调用 cmake
cmake -G Ninja -DCMAKE_CXX_COMPILER:PATH="C:\\MeineProgramme\\LLVM\\bin\\clang-cl.exe" -DCMAKE_LINKER:PATH="C:\\MeineProgramme\\LLVM\\bin\\lld-link.exe"\nRun Code Online (Sandbox Code Playgroud)\n\n这会产生完美的忍者构建文件并生成功能性可执行文件。
\n\n如果我想构建 x86 应用程序,CMake 无法检测构建环境。vcvars32我使用或初始化构建环境,vcvarsamd64_x86并使用与上面相同的命令来调用 CMake。这会导致在检测构建环境期间出现错误。
CMake错误日志有以下内容
\n\nCompiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.\nCompiler: C:/MeineProgramme/LLVM/bin/clang-cl.exe \nBuild flags: \nId flags: \n\nThe output was:\n1120\nLINK : error LNK2001: Nicht aufgel\xc3\xb6stes externes Symbol "mainCRTStartup".\nC:\\MeineProgramme\\Visual_Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.11.25503\\lib\\x86\\libcmt.lib : warning LNK4272:Bibliothekcomputertyp "x86" steht in Konflikt mit dem Zielcomputertyp "x64"\nCMakeCXXCompilerId.exe : fatal error LNK1120: 1 nicht aufgel\xc3\xb6ste Externe\nclang-cl.exe: error: linker command failed with exit code 1120 (use -v to see invocation)\n\n\nDetermining if the CXX compiler works failed with the following output:\nChange Dir: D:/Dateien/Downloads/Test/build/CMakeFiles/CMakeTmp\n\nRun Build Command:"C:/MeineProgramme/Ninja/bin/ninja.exe" "cmTC_e2ed5"\n[1/2] Building CXX object CMakeFiles\\cmTC_e2ed5.dir\\testCXXCompiler.cxx.obj\n\n[2/2] Linking CXX executable cmTC_e2ed5.exe\n\nFAILED: cmTC_e2ed5.exe \n\ncmd.exe /C "cd . && C:\\MeineProgramme\\CMake\\bin\\cmake.exe -E vs_link_exe --intdir=CMakeFiles\\cmTC_e2ed5.dir --manifests -- C:\\MeineProgramme\\LLVM\\bin\\lld-link.exe /nologo CMakeFiles\\cmTC_e2ed5.dir\\testCXXCompiler.cxx.obj /out:cmTC_e2ed5.exe /implib:cmTC_e2ed5.lib /pdb:cmTC_e2ed5.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 ."\n\nLINK Pass 1: command "C:\\MeineProgramme\\LLVM\\bin\\lld-link.exe /nologo CMakeFiles\\cmTC_e2ed5.dir\\testCXXCompiler.cxx.obj /out:cmTC_e2ed5.exe /implib:cmTC_e2ed5.lib /pdb:cmTC_e2ed5.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\\cmTC_e2ed5.dir/intermediate.manifest CMakeFiles\\cmTC_e2ed5.dir/manifest.res" failed (exit code 1) with the following output:\nC:\\MeineProgramme\\LLVM\\bin\\lld-link.exe: warning: <root>: undefined symbol: mainCRTStartup\n\nerror: link failed\n\nninja: build stopped: subcommand failed.\nRun Code Online (Sandbox Code Playgroud)\n\n据我了解,问题在于 CMake 传递/machine:x64给链接器。
我应该对 CMake 调用或 CMakeLists 进行哪些修改才能解决此问题?
\n\n很感谢任何形式的帮助。感谢你们 :-)
\nCMake 问题 #16259:“混合 64/32 位 clang 和 Visual Studio 环境时,Ninja 生成器因 clang-cl 失败”建议使用环境变量:
Ninja 生成器要求已经为编译器配置环境以生成所需的目标。你需要做
Run Code Online (Sandbox Code Playgroud)>set CC=clang-cl >set CFLAGS=-m32 >set CXX=clang-cl >set CXXFLAGS=-m32告诉 CMake 如何调用所需目标的编译器。
| 归档时间: |
|
| 查看次数: |
7597 次 |
| 最近记录: |