chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.38k stars 467 forks source link

build target libcef_dll_wrapper and cefclient simultaneously #3808

Closed copilot0058 closed 1 month ago

copilot0058 commented 1 month ago

Describe the bug simple build fail

To Reproduce Steps to reproduce the behavior:

  1. download binary https://cef-builds.spotifycdn.com/index.html
  2. build target libcef_dll_wrapper cefclient
    cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE="Release"
    cmake --build build --target libcef_dll_wrapper cefclient --config Release

Warning (it show the code is using the MT to build the target libcef_dll_wrapper cefclient) Ninja seem to use the setting that default is /MT

cl : command line warning D9025: Overriding '/MD' with '/MT'
  1. In order solve it, I try to set cmake /MD Follow this https://bitbucket.org/chromiumembedded/cef/wiki/LinkingDifferentRunTimeLibraries.md
    cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE="Release" -DCEF_RUNTIME_LIBRARY_FLAG="/MD"
    cmake --build build --target libcef_dll_wrapper cefclient --config Release 

it error

libcpmt.lib(StlLCMapStringA.obj) : error LNK2038: Mismatched 'RuntimeLibrary' detected: 'MT_StaticRelease' value does not match 'MD_DynamicRelease' value (located in base_client_handler.cc.obj)
   Building library tests\cefclient\cefclient.lib and object tests\cefclient\cefclient.exp
LINK : warning LNK4098

Expected behavior For the step 2, how to solve the warning cl : command line warning D9025: Overriding '/MD' with '/MT'

Because I try to build cef library, and if using the lib that build on step2, my projcet will show error detected: 'MT_StaticRelease' value does not match 'MD_DynamicRelease' value

here is my project Pseudocode

add_executable(test ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp )
target_link_libraries(test PUBLIC ${CEF_LIBRARIES})

Versions (please complete the following information):

magreenblatt commented 1 month ago

The sandbox is enabled by default, and linking the sandbox with /MD is not supported. See https://www.magpcss.org/ceforum/viewtopic.php?f=6&t=18592

copilot0058 commented 1 month ago

The sandbox is enabled by default, and linking the sandbox with /MD is not supported. See https://www.magpcss.org/ceforum/viewtopic.php?f=6&t=18592

According to your reply, so the libcef_dll_wrapper and cefclient should be the /MT. And my poject want to link the cef lib that build on /MT and it show the error

libcpmt.lib(StlLCMapStringA.obj) : error LNK2038: Mismatched 'RuntimeLibrary' detected: 'MT_StaticRelease' value does not match 'MD_DynamicRelease' value (located in base_client_handler.cc.obj)
   Building library tests\cefclient\cefclient.lib and object tests\cefclient\cefclient.exp
LINK : warning LNK4098

how can I set the cmake on my project?

magreenblatt commented 1 month ago

If you build everything with /MT then it shouldn’t be an issue.

copilot0058 commented 1 month ago

I have some question about

When I build the cefclient with this, it will generate the libcef.dll dynamic lib (/MT) at build folder

cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE="Release"
cmake --build build --target libcef_dll_wrapper cefclient --config Release

According to the message Overriding '/MD' with '/MT', assume the original libcef.dll dynamic lib (/MD) at Release

cef
├─build
│      ├─libcef_dll_wrapper
│      │            └─libcef_dll_wrapper.lib (static lib /MT)
│      └─tests
│           └─cefclient
│                 └─libcef.dll  (dynamic lib  /MT)
├─Release
        ├─  libcef.dll  (dynamic lib  /MD)
        └─  libcef.lib  (dynamic lib  /MD)

Is it correct?

magreenblatt commented 1 month ago

The libcef.dll provided in the binary distribution is built with /MT. If you disable the sandbox then libcef_dll_wrapper and cefclient can be built with /MD, otherwise they need to be built with /MT.

copilot0058 commented 1 month ago

I am confuse. If you say the libcef.dll provided in the binary distribution is built with /MT., it should not be show the warning Overriding '/MD' with '/MT'

[1/268] Building CXX object libcef_dll_wrapper\CMakeFiles\libcef_dll_wrapper.dir\shutdown_checker.cc.obj
cl : command  line warning D9025 : Overriding '/MD' with '/MT'

In fact, I use the default /MT to build, and it show Overriding '/MD' with '/MT'

the comment is using this command

cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE="Release"
cmake --build build --target libcef_dll_wrapper cefclient --config Release
-- *** CEF CONFIGURATION SETTINGS ***
-- Generator:                    Ninja
-- Platform:                     Windows
-- Project architecture:         x86_64
-- Build type:                   Release
-- Binary distribution root:     C:/tmp/cef/cef_binary_129.0.10+ge52707f+chromium-129.0.6668.71_windows64
-- Visual Studio ATL support:    ON
-- CEF sandbox:                  ON
-- Standard libraries:           comctl32.lib;gdi32.lib;rpcrt4.lib;shlwapi.lib;ws2_32.lib;Advapi32.lib;dbghelp.lib;Delayimp.lib;ntdll.lib;OleAut32.lib;PowrProf.lib;Propsys.lib;psapi.lib;SetupAPI.lib;Shell32.lib;Shcore.lib;Userenv.lib;version.lib;wbemuuid.lib;WindowsApp.lib;winmm.lib
-- Compile defines:              __STDC_CONSTANT_MACROS;__STDC_FORMAT_MACROS;WIN32;_WIN32;_WINDOWS;UNICODE;_UNICODE;WINVER=0x0A00;_WIN32_WINNT=0x0A00;NTDDI_VERSION=NTDDI_WIN10_FE;NOMINMAX;WIN32_LEAN_AND_MEAN;_HAS_EXCEPTIONS=0;PSAPI_VERSION=1;CEF_USE_SANDBOX;CEF_USE_ATL
-- Compile defines (Debug):      _HAS_ITERATOR_DEBUGGING=0
-- Compile defines (Release):    NDEBUG;_NDEBUG
-- C compile flags:              /MP;/Gy;/GR-;/W4;/WX;/wd4100;/wd4127;/wd4244;/wd4324;/wd4481;/wd4512;/wd4701;/wd4702;/wd4996;/Zi
-- C compile flags (Debug):      /MTd;/RTC1;/Od
-- C compile flags (Release):    /MT;/O2;/Ob2;/GF
-- C++ compile flags:            /MP;/Gy;/GR-;/W4;/WX;/wd4100;/wd4127;/wd4244;/wd4324;/wd4481;/wd4512;/wd4701;/wd4702;/wd4996;/Zi /std:c++17
-- C++ compile flags (Debug):    /MTd;/RTC1;/Od
-- C++ compile flags (Release):  /MT;/O2;/Ob2;/GF
-- Exe link flags:                /MANIFEST:NO;/LARGEADDRESSAWARE;/DELAYLOAD:api-ms-win-core-winrt-error-l1-1-0.dll;/DELAYLOAD:api-ms-win-core-winrt-l1-1-0.dll;/DELAYLOAD:api-ms-win-core-winrt-string-l1-1-0.dll;/DELAYLOAD:advapi32.dll;/DELAYLOAD:comctl32.dll;/DELAYLOAD:comdlg32.dll;/DELAYLOAD:credui.dll;/DELAYLOAD:cryptui.dll;/DELAYLOAD:d3d11.dll;/DELAYLOAD:d3d9.dll;/DELAYLOAD:dwmapi.dll;/DELAYLOAD:dxgi.dll;/DELAYLOAD:dxva2.dll;/DELAYLOAD:esent.dll;/DELAYLOAD:gdi32.dll;/DELAYLOAD:hid.dll;/DELAYLOAD:imagehlp.dll;/DELAYLOAD:imm32.dll;/DELAYLOAD:msi.dll;/DELAYLOAD:netapi32.dll;/DELAYLOAD:ncrypt.dll;/DELAYLOAD:ole32.dll;/DELAYLOAD:oleacc.dll;/DELAYLOAD:propsys.dll;/DELAYLOAD:psapi.dll;/DELAYLOAD:rpcrt4.dll;/DELAYLOAD:rstrtmgr.dll;/DELAYLOAD:setupapi.dll;/DELAYLOAD:shell32.dll;/DELAYLOAD:shlwapi.dll;/DELAYLOAD:uiautomationcore.dll;/DELAYLOAD:urlmon.dll;/DELAYLOAD:user32.dll;/DELAYLOAD:usp10.dll;/DELAYLOAD:uxtheme.dll;/DELAYLOAD:wer.dll;/DELAYLOAD:wevtapi.dll;/DELAYLOAD:wininet.dll;/DELAYLOAD:winusb.dll;/DELAYLOAD:wsock32.dll;/DELAYLOAD:wtsapi32.dll;/STACK:0x800000
-- 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_47.dll;libcef.dll;libEGL.dll;libGLESv2.dll;snapshot_blob.bin;v8_context_snapshot.bin;vk_swiftshader.dll;vk_swiftshader_icd.json;vulkan-1.dll;dxil.dll;dxcompiler.dll
-- CEF Resource files:           chrome_100_percent.pak;chrome_200_percent.pak;resources.pak;icudtl.dat;locales
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
magreenblatt commented 1 month ago

Overriding '/MD' with '/MT'

This means that /MT is being applied, but CMake has a default of /MD. Could be an issue with the Ninja generator.

copilot0058 commented 1 month ago

Is the conclusion right?

cef
├─build
│      ├─libcef_dll_wrapper
│      │            └─libcef_dll_wrapper.lib ( `static lib /MT`  or   `static lib  /MD` )  
│      └─tests
│           └─cefclient
│                 └─libcef.dll  (dynamic lib  /MD ,   just copy Release to here)
├─Release
        ├─  libcef.dll  (dynamic lib  /MD)
        └─  libcef.lib  (dynamic lib  /MD)
magreenblatt commented 1 month ago

See “Dynamic Linking” section of https://bitbucket.org/chromiumembedded/cef/wiki/LinkingDifferentRunTimeLibraries.md

copilot0058 commented 4 weeks ago

Yes, it is a good document. The document only say libcef_dll_wrapper can be build with /MD or /MT. And I already try build target libcef_dll_wrapper with /MD or /MT, it is always generate the *.lib. So my conclusion is libcef_dll_wrapper.lib ( static lib /MT or static lib /MD )

Another thing is libcef, the document doesn't show about libcef. According to other message, it show the libcef can not be build by distribution. It is already build https://github.com/chromiumembedded/cef/blob/030272fe4c2a093613fbbf539949b7ac62bebd80/cmake/cef_variables.cmake.in#L216-L225 Becuase cef doesn't say the souce about libcef.dll So I assume the conclusion is libcef.dll (dynamic lib /MD)