Chromium Embedded Framework build

Using windows and vs2022 prompt.
I try to download CEF binary distribution and build the libcef_dll_wrapper

I use this to download cef builds and command

cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE="Release"

cmake --build build --target libcef_dll_wrapper --config Release

and it warn

libcef_dll_wrapper.lib(command_line_ctocpp.obj) : error LNK2038: Mismatched 'RuntimeLibrary' detected: 'MT_StaticRelease' value does not match 'MD_DynamicRelease' value (located in main.obj)

I try to set and clean, it still warn.

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MD")  
# or
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")  

What do I miss?

https://cef-builds.spotifycdn.com/index.html

The CEF project file semi-hardcodes MSVC runtime flag in CEF_RUNTIME_LIBRARY_FLAG cache variable (in ./cmake/cef_variables.cmake), so you might want to patch that. Or provide desired value with -D on configuration.

I found the default is using /MT

And I use this to build the library

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

And link it with my project

add_executable(test ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp )
target_link_libraries(test PUBLIC ${CEF_LIBRARIES})
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

do you know why it use MD_DynamicRelease?
I alreay check the cef lib build with /MT

So it would seem that your project is using MD_DynamicRelease, wouldn’t it? Then you either set the same value on configuring CEF or set the CEF value on your project configuration. But what I would do is delete that entire block from CEF project file, as one rarely needs to hardcode MSVC runtime linking type, especially given that one’s project might be used in other people projects.

you are right.

If I build cef lib with /MT and link it to my project that build with vs2022.
Follow this message, the linker setting in your Visual Studio project are set to dynamically link (meaning the link will occur during runtime, usually with a .dll file).

But I create my project with cmake project, so I don’t have the IDE to set the Runtime Library.
Do you have the recommend cmake command to set the Runtime Library to static on my project ?

But I create my project with cmake project

Your question wouldn’t belong to this forum otherwise :slight_smile:

cmake command to set the Runtime Library

That can be done by setting MSVC_RUNTIME_LIBRARY to an appropriate value. There are several examples of this here already.

I have another question
Is it possible for the two case

  1. using /MT to build libcef_dll_wrapper.lib (static)
  2. using /MD to build libcef_dll_wrapper.lib (static)

or
It must be one by one
/MT => generate static lib
/MD => generate dynamic lib