JCHub

  • Home
  • Category
    • A/V
    • WebRTC
    • Beauty of Programming
    • Linux
    • Windows
    • Moments of Life
    • Campus Life
  • Reference
    • API Reference
    • Utilities
    • AV Test
    • Doc
  • Message Board
  • About
JCHub
Code as My Sword, Lost in Obsession
  1. Main page
  2. Windows
  3. Main content

libcef编译使用--使用VS2015

2015年11月20日 62649hotness 9likes 10comments

1.背景
现在好多客户端程序都内嵌浏览器,有的用于实现界面,有的用于实现一些特殊功能,比如网易云音乐,QQ客户端,微信桌面客户端等。如果要内嵌浏览器,传统的方法是加入自带的IE webbrowser activex控件,但是IE对html5标准的支持不是很好,无法完成一些最新的功能。此时webkit就是最好的选择,可是webkit是一个很复杂的工程,编译也非常麻烦。好在有人替我们完成这个工作。有个叫libcef的库,实现了对webkit的封装,我们只需要直接调用就可以了,从而往我们的程序嵌入webkit浏览器,实现我们需要的功能。上面说到的那三个软件都用到了libcef这个库,在这些程序的安装目录下我们可以看到libcef.dll,libEGL.dll等dll文件。

2.生成VS工程文件
从https://cefbuilds.com/下载预编译好的二进制包,我下载的是cef_binary_3.2526.1346.g1f86d24_windows32.7z,2526分支的32位版本。然后解压到本地,比如我的是D:\SDK\cef。虽然需要的dll以及两个lib文件已经帮我们编译好了,但此时libcef还不能直接使用,因为我们还需要libcef_dll_wrapper.lib这个文件,而这个需要我们自己编译,如果没有这个的话,我们运行里面的cefsimple:

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
 
#include <windows.h>
 
#include "cefsimple/simple_app.h"
#include "include/cef_sandbox_win.h"
 
 
// When generating projects with CMake the CEF_USE_SANDBOX value will be defined
// automatically if using the required compiler version. Pass -DUSE_SANDBOX=OFF
// to the CMake command-line to disable use of the sandbox.
// Uncomment this line to manually enable sandbox support.
// #define CEF_USE_SANDBOX 1
 
#if defined(CEF_USE_SANDBOX)
// The cef_sandbox.lib static library is currently built with VS2013. It may not
// link successfully with other VS versions.
#pragma comment(lib, "cef_sandbox.lib")
#endif
 
 
// Entry point function for all processes.
int APIENTRY wWinMain(HINSTANCE hInstance,
                      HINSTANCE hPrevInstance,
                      LPTSTR    lpCmdLine,
                      int       nCmdShow) {
  UNREFERENCED_PARAMETER(hPrevInstance);
  UNREFERENCED_PARAMETER(lpCmdLine);
 
  // Enable High-DPI support on Windows 7 or newer.
  CefEnableHighDPISupport();
 
  void* sandbox_info = NULL;
 
#if defined(CEF_USE_SANDBOX)
  // Manage the life span of the sandbox information object. This is necessary
  // for sandbox support on Windows. See cef_sandbox_win.h for complete details.
  CefScopedSandboxInfo scoped_sandbox;
  sandbox_info = scoped_sandbox.sandbox_info();
#endif
 
  // Provide CEF with command-line arguments.
  CefMainArgs main_args(hInstance);
 
  // SimpleApp implements application-level callbacks. It will create the first
  // browser instance in OnContextInitialized() after CEF has initialized.
  CefRefPtr<SimpleApp> app(new SimpleApp);
 
  // CEF applications have multiple sub-processes (render, plugin, GPU, etc)
  // that share the same executable. This function checks the command-line and,
  // if this is a sub-process, executes the appropriate logic.
  int exit_code = CefExecuteProcess(main_args, app.get(), sandbox_info);
  if (exit_code >= 0) {
    // The sub-process has completed so return here.
    return exit_code;
  }
 
  // Specify CEF global settings here.
  CefSettings settings;
 
#if !defined(CEF_USE_SANDBOX)
  settings.no_sandbox = true;
#endif
 
  // Initialize CEF.
  CefInitialize(main_args, settings, app.get(), sandbox_info);
 
  // Run the CEF message loop. This will block until CefQuitMessageLoop() is
  // called.
  CefRunMessageLoop();
 
  // Shut down CEF.
  CefShutdown();
 
  return 0;
}

会报如下错误:

1
2
3
4
5
6
7
8
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol "int __cdecl CefExecuteProcess(class CefMainArgs const &,class CefRefPtr<class CefApp>,void *)" (?CefExecuteProcess@@YAHABVCefMainArgs@@V?$CefRefPtr@VCefApp@@@@PAX@Z) referenced in function _wWinMain@16 cefsample D:\vs2015\cefsample\cefsample\Source.obj 1
Error LNK2019 unresolved external symbol "bool __cdecl CefInitialize(class CefMainArgs const &,class CefStructBase<struct CefSettingsTraits> const &,class CefRefPtr<class CefApp>,void *)" (?CefInitialize@@YA_NABVCefMainArgs@@ABV?$CefStructBase@UCefSettingsTraits@@@@V?$CefRefPtr@VCefApp@@@@PAX@Z) referenced in function _wWinMain@16 cefsample D:\vs2015\cefsample\cefsample\Source.obj 1
Error LNK2019 unresolved external symbol "void __cdecl CefShutdown(void)" (?CefShutdown@@YAXXZ) referenced in function _wWinMain@16 cefsample D:\vs2015\cefsample\cefsample\Source.obj 1
Error LNK2019 unresolved external symbol "void __cdecl CefRunMessageLoop(void)" (?CefRunMessageLoop@@YAXXZ) referenced in function _wWinMain@16 cefsample D:\vs2015\cefsample\cefsample\Source.obj 1
Error LNK2019 unresolved external symbol "void __cdecl CefEnableHighDPISupport(void)" (?CefEnableHighDPISupport@@YAXXZ) referenced in function _wWinMain@16 cefsample D:\vs2015\cefsample\cefsample\Source.obj 1
Error LNK2019 unresolved external symbol "public: __thiscall SimpleApp::SimpleApp(void)" (??0SimpleApp@@QAE@XZ) referenced in function _wWinMain@16 cefsample D:\vs2015\cefsample\cefsample\Source.obj 1
Error LNK1120 6 unresolved externals cefsample D:\vs2015\cefsample\Debug\cefsample.exe 1

都是些 referenced in function _wWinMain@16的错误。
要编译libcef_dll_wrapper.lib文件,需要我们去生成VS工程文件,然后用VS打开编译。此时我们需要用到cmake软件。如下图所示打开cmake软件,设置代码目录以及工程文件生成目录:
cmake libcef

接着点击Configure,选择编译器,我用的是默认VS2015自带的:
cmake libcef

然后点击Generate即在cef目录下生成VS工程文件:
cmake libcef

如下图,目录下已经生成了cef.sln解决方案文件,此时我们打开cef.sln文件
cmake libcef

可以看到该解决方案下有5个工程:
cmake libcef

编译libcef_dll_wrapper工程即可得到libcef_dll_wrapper.lib文件,然后我们编译运行示例工程cefclient,即可看到一个简单的浏览器,很简单吧。
libcef demo

This article is licensed with Creative Commons Attribution-NonCommercial-No Derivatives 4.0 International License
Tag: C++
Last updated:2018年12月23日

Jeff

管理员——代码为剑,如痴如醉

Tip the author Like
Next article >

Comments

  • 骑驴

    觉得libcef前景怎么样,和electron有对比性吗?

    2016年9月5日
    Reply
    • Jianchihu

      @骑驴 electron不了解

      2016年9月6日
      Reply
      • 骑驴

        @Jianchihu 这几天稍微了解了一下,libcef不太稳定。electron易用性较高。

        2016年9月8日
        Reply
        • Jianchihu

          @骑驴 libcef这么多大公司都在用,不可能不稳定吧。

          2016年9月10日
          Reply
  • xx

    他山界面开发框架是一套基于Gecko的开源收费跨平台界面解决方案。可使用xul, html(5), css(3), js 开发界面,支持js, c++互调,发行包大小13MB 。

    2017年7月2日
    Reply
  • Jianchihu

    yes我擦,广告都打我这里来了。还有这种鸟界面库。

    2017年7月3日
    Reply
  • 他山

    哪里鸟了?不比cef强?

    2018年2月6日
    Reply
    • 菜菜

      @他山 是真的鸟

      2021年1月15日
      Reply
  • AndrewGor

    <a href=https://novostic.ru>пенсионный фонд России</a> - пенсия работающим пенсионерам, Наука и технологии

    2020年6月22日
    Reply
  • SanuyemScume

    Localized microdontia is widespread, most incessantly affecting the maxillary lateral incisors which may turn out to be slender and tapered (peg-formed). Palliative care may be offered anytime during a person’s illness, even from the time of diagnosis. A variety of major glomerular and systemic ailments are characterised by formation of crescents allergy dry cough [url=https://www.dpps.gov.mm/medicine/Promethazine.html]purchase promethazine 25 mg[/url].
    Background Benefit/Coverage/Program Information Additional Clinical Rules: Supply limits could also be in place. Both exams provide a sample of tissue from the placenta or amniotic fluid that has the same genetics as the baby. Several works within the short time period for quickly progressive types, in an have described good ends in percentiles that vary try and brake that progression and different thera- from 29 to 87% of the circumstances handled managing diabetes with diet and exercise alone [url=https://www.dpps.gov.mm/medicine/Precose.html]discount precose 50 mg with amex[/url]. However, interspersed among the exocrine cells are clusters of cells often known as the islets of Langerhans, which secrete the hormones insulin and glucagon (and small portions of somatostatin and several other minor hormones). Although it is technically possible there's not been totally investigated and clarified. The last focus of the diluted solution ought to be between 1 mg/mL to 10 mg/mL arteria musculophrenica [url=https://www.dpps.gov.mm/medicine/Coumadin.html]coumadin 1 mg otc[/url]. We are only aware of 1 previous crease the probability of vaccination via increased examine taking an identical strategy: A U. In addition, the appliance often needs to be sectioned or parts of the occlusal plastic removed for a direct purchase on the teeth so the band remover can effectively lift and separate the plastic from the teeth. The epidemiology and genetics of most cancers susceptibility genetic variants in sporadic and hereditary testicular germ high-threat men initially identifed from cell tumors women's health center waco [url=https://www.dpps.gov.mm/medicine/Provera.html]buy provera 5 mg online[/url]. Type of bodily exercise carried out When you're bodily lively, what sort of activity do you normally performfi. Economic analysis of alternative assisted replica techniques in administration of infertility in Greece. Sit along with your legs crossed, your chest up tall, and your arms out in front of you weight loss pills lipozene [url=https://www.dpps.gov.mm/medicine/Alli.html]discount 60 mg alli with visa[/url].

    2026年4月3日
    Reply
  • razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
    Cancel

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Related Posts
    • 基于FireBreath的npapi插件在Firefox下的调试
    • Nodejs C++ addon开发简介
    • Google C++ style Guide图解
    • FireBreath插件IE浏览器中文字符乱码问题
    • web页面npapi插件资源管理问题
    Categories

    COPYRIGHT © 2026 jianchihu.net. ALL RIGHTS RESERVED.

    Theme Kratos Made By Seaton Jiang