我已按照以下指南设置了Windows docker容器来构建msvc项目:https://devblogs.microsoft.com/cppblog/using-msvc-in-a-docker-container-for-your-c-projects/
我正在使用cmake进行构建,但是无法设置编译器选项,因此无法进行构建。我需要设置/ Z7(调试信息格式)以便能够在docker容器中构建,否则,我将收到错误消息:
LINK:致命错误LNK1318:意外的PDB错误
我知道这是问题所在,因为如果我在CMakeCache.txt文件中手动设置/ Z7,它将生成。
我尝试使用目标编译选项,add_compile_options和设置(CMAKE_CXX_FLAGS_DEBUG ...)。
这是我目前的CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.9)
project (ConsoleApplication1)
add_executable(ConsoleApplication1 ConsoleApplication1.cpp)
target_compile_options(ConsoleApplication1 PRIVATE /Z7 /W4)
该应用程序是通过VS2017创建的默认ConsoleApplication。
完整的错误消息: 完整的错误消息:
PS C:\consoleapplication1\build> cmake ..
-- Building for: Visual Studio 15 2017
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.16299.
-- The C compiler identification is MSVC 19.16.27030.1
-- The CXX compiler identification is MSVC 19.16.27030.1
-- Check for working C compiler: C:/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
CMake Error: Remove failed on file: C:/consoleapplication1/build/CMakeFiles/CMakeTmp/Debug/cmTC_714d8.pdb: System Error: No such file or directory
-- Check for working C compiler: C:/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- broken
CMake Error at C:/BuildTools/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"C:/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/consoleapplication1/build/CMakeFiles/CMakeTmp
Run Build Command:"C:/BuildTools/MSBuild/15.0/Bin/MSBuild.exe" "cmTC_714d8.vcxproj" "/p:Configuration=Debug" "/p:VisualStudioVersion=15.0"
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 7/4/2019 1:01:26 PM.
Project "C:\consoleapplication1\build\CMakeFiles\CMakeTmp\cmTC_714d8.vcxproj" on node 1 (default targets).
PrepareForBuild:
Creating directory "cmTC_714d8.dir\Debug\".
Creating directory "C:\consoleapplication1\build\CMakeFiles\CMakeTmp\Debug\".
Creating directory "cmTC_714d8.dir\Debug\cmTC_714d8.tlog\".
InitializeBuildStatus:
Creating "cmTC_714d8.dir\Debug\cmTC_714d8.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
C:\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\CL.exe /c /Zi /W3 /WX- /diagnostics:classic /Od /Ob0 /Oy- /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_714d8.dir\Debug\\" /Fd"cmTC_714d8.dir\Debug\vc141.pdb" /Gd /TC /analyze- /FC /errorReport:queue C:\consoleapplication1\build\CMakeFiles\CMakeTmp\testCCompiler.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27030.1 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
cl /c /Zi /W3 /WX- /diagnostics:classic /Od /Ob0 /Oy- /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_714d8.dir\Debug\\" /Fd"cmTC_714d8.dir\Debug\vc141.pdb" /Gd /TC /analyze- /FC /errorReport:queue C:\consoleapplication1\build\CMakeFiles\CMakeTmp\testCCompiler.c
testCCompiler.c
Link:
C:\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\link.exe /ERRORREPORT:QUEUE /OUT:"C:\consoleapplication1\build\CMakeFiles\CMakeTmp\Debug\cmTC_714d8.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:/consoleapplication1/build/CMakeFiles/CMakeTmp/Debug/cmTC_714d8.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:/consoleapplication1/build/CMakeFiles/CMakeTmp/Debug/cmTC_714d8.lib" /MACHINE:X86 /SAFESEH /machine:X86 cmTC_714d8.dir\Debug\testCCompiler.obj
LINK : fatal error LNK1318: Unexpected PDB error; RPC (23) '(0x000006E7)' [C:\consoleapplication1\build\CMakeFiles\CMakeTmp\cmTC_714d8.vcxproj]
Done Building Project "C:\consoleapplication1\build\CMakeFiles\CMakeTmp\cmTC_714d8.vcxproj" (default targets) -- FAILED.
Build FAILED.
"C:\consoleapplication1\build\CMakeFiles\CMakeTmp\cmTC_714d8.vcxproj" (default target) (1) ->
(Link target) ->
LINK : fatal error LNK1318: Unexpected PDB error; RPC (23) '(0x000006E7)' [C:\consoleapplication1\build\CMakeFiles\CMakeTmp\cmTC_714d8.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:01.55
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred!
See also "C:/consoleapplication1/build/CMakeFiles/CMakeOutput.log".
See also "C:/consoleapplication1/build/CMakeFiles/CMakeError.log".
有人能做到这一点吗:docker windows容器,cmake,msvc?我会对看到您曾经使用过的CMakeLists.txt非常感兴趣。
编辑:添加了CMakeLists.txt和完整的错误输出
答案 0 :(得分:0)
正如Tsyvarev所注意到的那样,问题在于编译器正在检查而不是在编译我的代码,它与构建绑定安装有关,如此处所述:https://github.com/docker/for-win/issues/829#issuecomment-397149736
因为在项目文件中设置“调试信息格式”(链接中的替代方法B)对我来说不是解决方案,所以我找到了一种替代方法来跳过编译器检查。这是对我有用的CMakeLists.txt。
naked_object = muterun_js('script.js')
print("Output", naked_object.stdout.decode("utf-8"))
我不确定设置COMPILER_FORCED是否有副作用,但是至少它允许我在Docker容器中进行构建。
这里也是向MS报告有关此问题的错误:https://developercommunity.visualstudio.com/content/problem/607325/lnk1318-unexpected-pdb-error-when-building-from-a.html