剑痴乎

  • 首页
  • 文章分类
    • 音视频
    • WebRTC
    • 编程之美
    • Linux
    • Windows
    • 生活点滴
    • 校园生活
  • 参考
    • API参考
    • 实用工具
    • 测试音视频
    • 文档
  • 留言板
  • 关于
剑痴乎
代码为剑,如痴如醉
  1. 首页
  2. Windows
  3. 正文

libcef编译使用--使用VS2015

2015年11月20日 45938点热度 9人点赞 9条评论

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

本作品采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 进行许可
标签: C++
最后更新:2018年12月23日

Jeff

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

打赏 点赞
下一篇 >

文章评论

  • 骑驴

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

    2016年9月5日
    回复
    • Jianchihu

      @骑驴 electron不了解

      2016年9月6日
      回复
      • 骑驴

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

        2016年9月8日
        回复
        • Jianchihu

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

          2016年9月10日
          回复
  • xx

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

    2017年7月2日
    回复
  • Jianchihu

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

    2017年7月3日
    回复
  • 他山

    哪里鸟了?不比cef强?

    2018年2月6日
    回复
    • 菜菜

      @他山 是真的鸟

      2021年1月15日
      回复
  • AndrewGor

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

    2020年6月22日
    回复
  • razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
    回复 Jianchihu 取消回复

    这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理。

    版权声明

    为支持原创,创作更好的文章,未经许可,禁止任何形式的转载与抄袭,如需转载请邮件私信!本人保留所有法定权利。违者必究!

    最近评论
    ztt 发布于 1 个月前(04月05日) 你好,想看里面的视频和图片为什么没有显示呢?需要下flash吗还是什么。
    huowa222 发布于 1 个月前(03月26日) 同问
    邱国禄 发布于 3 个月前(02月17日) Receive Delta以0.25ms为单位,reference time以64ms为单位,kDe...
    啊非 发布于 4 个月前(12月30日) 大神,请教一个问题: constexpr int kBaseScaleFactor = Tran...
    啊非 发布于 4 个月前(12月30日) reference time:3字节,表示参考时间,以64ms为单位,但是 代码里面是 Trans...
    相关文章
    • 基于FireBreath的npapi插件在Firefox下的调试
    • FireBreath插件IE浏览器中文字符乱码问题
    • web页面npapi插件资源管理问题
    • Win10任务管理器GPU信息
    • DXGI中的flip显示模型

    COPYRIGHT © 2024 jianchihu.net. ALL RIGHTS RESERVED.

    Theme Kratos Made By Seaton Jiang