程序员

libcef在win10下的manifest问题

2023-11-30  本文已影响0人  拉普拉斯妖kk

在win10下集成libcef的项目运行时可能看到一个白屏的浏览器窗口,查日志发现报错:

Check failed: fallback_available == base::win::GetVersion() > base::win::Version::WIN8 (1 vs. 0)

这是因为浏览器程序加载不到manifest文件,导致操作系统版本处理错误。

关于这个错误CEF官方的解答是这样的:Check failed: fallback_available

微软官方的解释是这样的:让你的应用程序面向 Windows

解决方案

第一种解决方案,可以通过创建一个manifest文件添加到工程项目中。具体步骤如下:

<?xml version="1.0" encoding="utf-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">  
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">  
    <application> 
        <!-- Windows 10 and Windows 11 -->
        <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
        <!-- Windows 8.1 -->
        <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
        <!-- Windows 8 -->
        <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
    </application> 
  </compatibility> 
</assembly>

第二种解决方案主要参考了CEF提供的示例程序——cefsimple。具体步骤如下:

setlocal
mt.exe -nologo -manifest "compatibility.manifest" "xxx.exe.manifest" -outputresource:"your/path/xxx.exe";#1
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
 
if %errorlevel% neq 0 goto :VCEnd

以上,重新编译程序后就可以看到浏览器正确加载网页,再无报错信息。

优化

针对第二种解决方案,如果vs工程文件是通过cmake生成的还可以参考cefsimple中的cmake脚本优化下。

# Add custom manifest files to an executable target.
macro(ADD_WINDOWS_MANIFEST manifest_path target extension)
  add_custom_command(
    TARGET ${target}
    POST_BUILD
    COMMAND "mt.exe" -nologo
            -manifest \"${manifest_path}/${target}.${extension}.manifest\" \"${manifest_path}/compatibility.manifest\"
            -outputresource:"${CEF_TARGET_OUT_DIR}/${target}.${extension}"\;\#1
    COMMENT "Adding manifest..."
    )
endmacro()
# Add the custom manifest files to the executable.
  ADD_WINDOWS_MANIFEST("${CMAKE_CURRENT_SOURCE_DIR}" "${YOUR_TARGET}" "exe")
上一篇 下一篇

猜你喜欢

热点阅读