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 小时前
Windows 10 Android 构建配置指南
android·windows
雨中风华9 小时前
Linux, macOS系统实现远程目录访问(等同于windows平台xFsRedir软件的目录重定向)
linux·windows·macos
yuuki23323311 小时前
【C++】继承
开发语言·c++·windows
非凡ghost11 小时前
PowerDirector安卓版(威力导演安卓版)
android·windows·学习·软件需求
小毛驴85011 小时前
Linux curl 命令用法
linux·运维·chrome
John_ToDebug12 小时前
Chromium安全架构深度解析:从悬空指针检测到内存安全防御体系
c++·chrome
疯狂敲代码的老刘13 小时前
JDK 1.6到25 全版本网盘合集 (Windows + Mac + Linux)
java·linux·windows·macos·jdk
怣5014 小时前
MySQL子查询实战指南:数据操作(增删改查)与通用表达式
数据库·chrome·mysql
love530love14 小时前
Windows 下 GCC 编译器安装与排错实录
人工智能·windows·python·gcc·msys2·gtk·msys2 mingw 64
John_ToDebug14 小时前
Chromium回调机制的隐秘角落:当const &参数遇见base::BindOnce
c++·chrome·性能优化