libcef在win10下的manifest问题

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

ruby 复制代码
Check failed: fallback_available == base::win::GetVersion() > base::win::Version::WIN8 (1 vs. 0)

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

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

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

解决方案

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

  • 在工程目录中创建一个manifest文件------xxx.manifest(xxx是可以工程名字或者其他有意义的),文件内容如下:
xml 复制代码
<?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>
  • 在项目工程中添加这个manifest文件,添加路径是:在vs项目属性中找到清单工具 ------ 输入和输出 ------ 附加清单文件,添加上刚刚创建的xxx.manifest。

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

  • 拷贝CEF源码中示例程序cefsimple中的 cefsimple.exe.manifest 和 compatibility.manifest (在test\cefsimple中)两个文件到的工程目录下面,并且将cefsimple.exe.manifest名称修改为xxx.exe.manifest(xxx是可以工程名字或者其他有意义的)。
  • 在后期生成事件中加上添加manifest的脚本,添加路径是:在vs项目属性中找到 生成事件 ------ 后期生成事件 ------ 命令行,添加上如下命令,注意替换compatibility.manifest、xxx.exe.manifest和your/path/xxx.exe为你自己的路径,可以用绝对路径:
ruby 复制代码
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脚本优化下。

  • 在CEF工程的cmake文件夹中cef_macros.cmake文件中定义了一个宏:
bash 复制代码
# 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()
  • 将它定义到生成vs工程文件的CMakeLists.txt中,然后添加如下内容(参考test\cefsimple中的CMakeLists.txt),注意修改${YOUR_TARGET}为工程名称。
bash 复制代码
# Add the custom manifest files to the executable.
  ADD_WINDOWS_MANIFEST("${CMAKE_CURRENT_SOURCE_DIR}" "${YOUR_TARGET}" "exe")
  • 如果工程编译出来的不是exe,而是dll,需要修改上面ADD_WINDOWS_MANIFEST中最后一个参数为"dll",相应的也需要修改xxx.exe.manifest文件名为xxx.dll.manifest。
相关推荐
_大学牲2 小时前
禁止复制内容 🤔 那点事~
前端·chrome·程序员
0xSec笔记本挖呀瓦呀挖4 小时前
电子取证之windows知识点:从 0 到 1 掌握 Windows 事件日志取证:以 玄机靶场-第五章 Windows 实战-evtx 文件分析
windows
莫生灬灬5 小时前
[特殊字符] FBro工作流自动化平台 - 让浏览器自动化更简单
运维·chrome·c#·自动化
星释7 小时前
鸿蒙Flutter三方库适配指南: 05.使用Windows搭建开发环境
windows·flutter·harmonyos
炒茄子17 小时前
Windows:解决电脑开机解锁后黑屏但鼠标可见可移动的问题
windows·计算机外设
shada17 小时前
从Google Chrome商店下载CRX文件
前端·chrome
luyun0202021 天前
流批了,pdf批量转excel
windows·pdf·excel·figma
熊明才1 天前
解决WSL2实例IP冲突:为多个WSL实例配置独立静态IP
chrome·网络协议·tcp/ip
vortex51 天前
在 Windows 系统中安装 Oracle、SQL Server(MSSQL)和 MySQL
windows·oracle·sqlserver
路由侠内网穿透1 天前
本地部署开源物联网平台 ThingsBoard 并实现外部访问( Windows 版本)
运维·服务器·windows·物联网·开源