如何在Windows下不使用Visual Studio编译CEF生成.exe文件
Compiling CEF Binaries & Building .exe from Source on Windows (No Visual Studio)
Got it, let’s walk through how to get this done using MinGW or command-line tools—no Visual Studio required. I’ve broken this into two main parts: compiling the CEF binaries themselves, and building your own .exe from CEF source code.
Prerequisites First
Before diving in, make sure you have these tools installed:
- MinGW-w64: Grab a recent version (x86_64 architecture recommended) with support for C++17 or later.
- CMake: Needed to generate build files for MinGW/Ninja.
- Ninja (optional but recommended): Faster than MinGW Makefiles for large projects like CEF.
- Python 3: CEF’s build scripts rely on Python to handle dependencies and configuration.
Part 1: Compile CEF Binaries with MinGW
- Extract your CEF source package to a directory (e.g.,
C:\cef_source). Avoid spaces in the path—they can cause build errors. - Open the MinGW-w64 Prompt (or a terminal where MinGW is in your PATH) and navigate to the CEF source directory.
- Create a build folder to keep source and build files separate:
mkdir build && cd build - Run CMake to generate MinGW-compatible build files. If your CEF dependencies are in a separate location, add
-DCEF_ROOT_DIR=path/to/cef/depsto the command:
Note: Disabling the sandbox (cmake -G "MinGW Makefiles" .. -DCEF_ENABLE_SANDBOX=OFFCEF_ENABLE_SANDBOX=OFF) is often necessary for MinGW builds, as Chromium’s sandbox has limited support with MinGW. - Start the compilation. Use
-jfollowed by your CPU core count to speed things up (e.g.,-j4for 4 cores):mingw32-make -j4 - Once done, your compiled binaries will be in the
build/Releaseorbuild/Debugfolder, depending on your CMake configuration.
Part 2: Build Your Own .exe from CEF Source
If you want to create a custom CEF-based application (not just compile the core binaries), here’s how:
- Write your CEF application code (e.g.,
main.cpp). You can use CEF’scefclientexample as a starting point—it’s included in the CEF source package. - Create a
CMakeLists.txtfile to link your code with CEF. Here’s a minimal example:cmake_minimum_required(VERSION 3.10) project(MyCEFApp) # Point to your CEF source directory set(CEF_ROOT_DIR "C:/cef_source") include(${CEF_ROOT_DIR}/cmake/cef_variables.cmake) # Add your executable and link CEF libraries add_executable(MyCEFApp main.cpp) target_link_libraries(MyCEFApp ${CEF_STATIC_LIBRARIES}) target_include_directories(MyCEFApp PRIVATE ${CEF_INCLUDE_DIRS}) - Repeat the build steps from Part 1: create a build folder, run CMake with MinGW Makefiles, then compile with
mingw32-make. Your custom.exewill appear in the build directory.
Using Command-Line with Ninja (Alternative to MinGW Makefiles)
If you prefer Ninja for faster builds:
- When running CMake, use the Ninja generator instead:
cmake -G Ninja .. -DCEF_ENABLE_SANDBOX=OFF - Compile with:
ninja
Quick Notes
- CEF builds are resource-heavy—expect the first compile to take a while (30+ minutes depending on your hardware).
- If you run into linker errors, double-check that MinGW’s architecture matches your CEF source (x86_64 vs x86).
- Some advanced CEF features (like GPU acceleration) might have limited support with MinGW—test thoroughly if your app relies on these.
内容的提问来源于stack exchange,提问作者a verma
相关产品推荐
相关产品推荐

