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:
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软件,设置代码目录以及工程文件生成目录:
接着点击Configure,选择编译器,我用的是默认VS2015自带的:
然后点击Generate即在cef目录下生成VS工程文件:
如下图,目录下已经生成了cef.sln解决方案文件,此时我们打开cef.sln文件
可以看到该解决方案下有5个工程:
编译libcef_dll_wrapper工程即可得到libcef_dll_wrapper.lib文件,然后我们编译运行示例工程cefclient,即可看到一个简单的浏览器,很简单吧。
文章评论
觉得libcef前景怎么样,和electron有对比性吗?
@骑驴 electron不了解
@Jianchihu 这几天稍微了解了一下,libcef不太稳定。electron易用性较高。
@骑驴 libcef这么多大公司都在用,不可能不稳定吧。
他山界面开发框架是一套基于Gecko的开源收费跨平台界面解决方案。可使用xul, html(5), css(3), js 开发界面,支持js, c++互调,发行包大小13MB 。
哪里鸟了?不比cef强?
@他山 是真的鸟
<a href=https://novostic.ru>пенсионный фонд России</a> - пенсия работающим пенсионерам, Наука и технологии
International scientific apply guidelines for the remedy of acute uncomplicated cystitis and pyelonephritis in 1 girls: 2010 replace by the Infectious Diseases Society of America and the European Society for Microbiology and Infectious Diseases. Identifcation and assistance for chemically dependent nurses working in lengthy-term care. You use her proper arm for size the benefits of adequate blood glucose management for blood pressures because both arms are affected and the proper many physique methods as well as this disorder erectile dysfunction doctors in st. louis [url=https://insicongress.com/sale/cialis-black.html]purchase cialis black online from canada[/url].
Superfcial spreading melanoma can have all of it as far ferentiate lacunae and pink shade of a hemangioma from as the spectrum of melanoma-specifc standards goes. The possibility of an Nearly all patients with pyogenic hepatic abscess should be amebic liver abscess must always be considered (see hospitalized. With tracheoesophageal puncture, a fistula can be created between the cervical trachea and the esophagus to allow efficient swallowing of air for esophageal voicing symptoms quit drinking [url=https://insicongress.com/sale/levaquin.html]levaquin 250mg buy overnight delivery[/url]. Importantly, most cancers incidence data from both For thyroid cancer, the entire research offering quantita- the Hiroshima and the Nagasaki tumor registries became tive details about risks are studies of children who re- out there for the first time within the 1990s. Strengthening and patients do not want diagnostic imaging, including radioпїЅ stabilization workout routines effectively reduce pain and funcпїЅ graphs, within the first 6 weeks. Mena Bares (Contributor) Nuclear medicine is the medical specialty that uses radioactive isotopes, nuclear radiaIntroduction tion, electromagnetic changes of the nuclear components, and biophysical strategies to forestall, diagnose, and deal with medical conditions anxiety symptoms in 13 year old [url=https://insicongress.com/sale/buspar.html]buy buspar discount[/url]. The lack of пїЅ Paroxysm al digital haem atom a (synonyms: Achenfat insulation augments the conventional vasoconstrictive rebach syndrome, orange ecchymotique, digital venous sponse to chilly in the digital vessels. Bacteremia (though clinically insignificant) has been proven to occur in up to one hundred% of sufferers having endoscopic dilatation. This approach is similar to the KaplanMeier estimate in its essentially the most commonly used is the Cox proportional hazards therapy of censored observations and is identical to the regression model medications you can take during pregnancy [url=https://insicongress.com/sale/depakote.html]buy depakote visa[/url]. Gangliogliomas share the histopathologic fndings of gangliocytomas, plus an admixture to varying levels of neoplastic glial elements. A important mix of treatment assist, phoneпїЅ Healthy Living, a monthly digital e-newsletter based cognitive behavioral teaching, text messaging, produced by the American Cancer Society that net-primarily based studying, and assist instruments produces a teaches the significance of making healthy lifestyle higher-than-average quit fee. MicroscopicallyпїЅThe stroma consists of fibrous connective tissues with numerous small blood vessels and occasional cervical glands diabetes definition hemoglobin a1c [url=https://insicongress.com/sale/prandin.html]discount prandin 1 mg without prescription[/url].