我目前正在尝试实现一个基于Chromium嵌入式框架(CEF)的软件。
我的目标平台是windows,我使用的是CEF Automated构建的最新版本(截至本文发布之日)。
由于与其他项目的兼容性原因,我需要将运行库分别指定为Debug和Release的/MD,并决定测试构建所提供的示例。我还使用了CEF指南中指出的make例程。
为此,我更改了文件cef_variables.cmake。特别是,我将cef_COMPILER_FLAGS_DEBUG和cef_COMPILER_FLAGS_RELEASE更改为
list(APPEND CEF_COMPILER_FLAGS_DEBUG
/MDd # Multithreaded debug runtime
/RTC1 # Disable optimizations
/Od # Enable basic run-time checks
)
list(APPEND CEF_COMPILER_FLAGS_RELEASE
/MD # Multithreaded release runtime
/O2 # Optimize for maximum speed
/Ob2 # Inline any suitable function
/GF # Enable string pooling
)
默认标志为/MTd和/MT。
使用默认标志时似乎没有问题,libcef_dll_wrapper和cefclient项目编译都很好。
然而,当使用更改后的标志时,我只能构建libcef_dll_wrapper,而构建cefclient会抛出以下链接器错误
Severity Code Description Project File Line Suppression State
Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in binding_test.obj cefclient D:WorkspaceCEFbuildtestscefclientcef_sandbox.lib(at_exit.obj)
cmake命令的输出为
-- The C compiler identification is MSVC 19.0.24215.1
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working C compiler: D:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
-- Check for working C compiler: D:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: D:/Program Files (x86)/Microsoft Visual Studi o 14.0/VC/bin/cl.exe
-- Check for working CXX compiler: D:/Program Files (x86)/Microsoft Visual Studi o 14.0/VC/bin/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- *** CEF CONFIGURATION SETTINGS ***
-- Generator: Visual Studio 14 2015
-- Platform: Windows
-- Project architecture: x86
-- Binary distribution root: D:/Workspace/CEF
-- CEF Windows sandbox: ON
-- Visual Studio ATL support: ON
-- Standard libraries: comctl32.lib;rpcrt4.lib;shlwapi.lib;ws2_32.lib; dbghelp.lib;psapi.lib;version.lib;winmm.lib
-- Compile defines: __STDC_CONSTANT_MACROS;__STDC_FORMAT_MACROS;WIN 32;_WIN32;_WINDOWS;UNICODE;_UNICODE;WINVER=0x0601;_WIN32_WINNT=0x601;NOMINMAX;WI N32_LEAN_AND_MEAN;_HAS_EXCEPTIONS=0;PSAPI_VERSION=1;CEF_USE_SANDBOX;CEF_USE_ATL
-- Compile defines (Debug):
-- Compile defines (Release): NDEBUG;_NDEBUG
-- C compile flags: /MP;/Gy;/GR-;/W4;/WX;/wd4100;/wd4127;/wd4244;/w d4481;/wd4512;/wd4701;/wd4702;/wd4996;/Zi
-- C compile flags (Debug): /MDd;/RTC1;/Od
-- C compile flags (Release): /MD;/O2;/Ob2;/GF
-- C++ compile flags: /MP;/Gy;/GR-;/W4;/WX;/wd4100;/wd4127;/wd4244;/w d4481;/wd4512;/wd4701;/wd4702;/wd4996;/Zi
-- C++ compile flags (Debug): /MDd;/RTC1;/Od
-- C++ compile flags (Release): /MD;/O2;/Ob2;/GF
-- Exe link flags: /MANIFEST:NO;/LARGEADDRESSAWARE
-- Exe link flags (Debug): /DEBUG
-- Exe link flags (Release):
-- Shared link flags:
-- Shared link flags (Debug): /DEBUG
-- Shared link flags (Release):
-- CEF Binary files: chrome_elf.dll;d3dcompiler_43.dll;d3dcompiler_4 7.dll;libcef.dll;libEGL.dll;libGLESv2.dll;natives_blob.bin;snapshot_blob.bin
-- CEF Resource files: cef.pak;cef_100_percent.pak;cef_200_percent.pak ;cef_extensions.pak;devtools_resources.pak;icudtl.dat;locales
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Workspace/CEF/build
我在这里错过了什么?我想,如果我更改了宏变量,所有的项目都将使用相同的设置构建,因此编译时不会出错。
我一直在继续研究,发现在使用自动构建时,它使用官方的cef_sandbox.lib,它使用/MTd和/MT运行时。
我的解决方案是更改宏变量,并将USE_SANDBOX设置为关闭。我仍然有一些错误,但现在cefclient正确编译