无法编译简单的C 程序
Cannot compile simple C++ program
我下载了以下C 库(商业无头浏览器)http://wiki.awesomium.com/。我打开了包装,目录结构看起来像这样:
/opt/awesomium_v1.7.2_sdk_linux64/bin
包含文件:
awesomium_pak_utility awesomium_process awesomium_sample_webflow libawesomium-1-7.so.2.0
以下路径包括包含文件:
/opt/awesomium_v1.7.2_sdk_linux64/include/Awesomium# ls
BitmapSurface.h DataSource.h JSValue.h ResourceInterceptor.h WebConfig.h WebKeyboardEvent.h WebSession.h WebTouchEvent.h WebViewListener.h
ChildProcess.h JSArray.h Platform.h STLHelpers.h WebCore.h WebMenuItem.h WebStringArray.h WebURL.h
DataPak.h JSObject.h PrintConfig.h Surface.h WebKeyboardCodes.h WebPreferences.h WebString.h WebView.h
因此,我尝试编译的软件包中包含一个非常简单的演示代码示例:
/opt/awesomium_v1.7.2_sdk_linux64/samples/hello# cat main.cc
/**
* This is a simple "Hello World!" example of using Awesomium.
*
* It loads a page and saves a rendered bitmap of it to a JPEG.
*
* Procedure:
* -- Create the WebCore singleton
* -- Create a new WebView and request for it to load a URL.
* -- Wait for the WebView to finish loading.
* -- Retrieve the BitmapSurface from the WebView.
* -- Save the BitmapSurface to 'result.jpg'.
* -- Clean up.
*/
// Various included headers
#include <Awesomium/WebCore.h>
#include <Awesomium/BitmapSurface.h>
#include <Awesomium/STLHelpers.h>
#include <iostream>
#if defined(__WIN32__) || defined(_WIN32)
#include <windows.h>
#elif defined(__APPLE__)
#include <unistd.h>
#endif
// Various macro definitions
#define WIDTH 800
#define HEIGHT 600
#define URL "http://www.google.com"
using namespace Awesomium;
// Forward declaration of our update function
void Update(int sleep_ms);
// Our main program
int main() {
// Create the WebCore singleton with default configuration
WebCore* web_core = WebCore::Initialize(WebConfig());
// Create a new WebView instance with a certain width and height, using the
// WebCore we just created
WebView* view = web_core->CreateWebView(WIDTH, HEIGHT);
// Load a certain URL into our WebView instance
WebURL url(WSLit(URL));
view->LoadURL(url);
std::cout << "Page is now loading..." << std::endl;;
// Wait for our WebView to finish loading
while (view->IsLoading())
Update(50);
std::cout << "Page has finished loading." << std::endl;
std::cout << "Page title is: " << view->title() << std::endl;
// Update once more a little longer to allow scripts and plugins
// to finish loading on the page.
Update(300);
// Get the WebView's rendering Surface. The default Surface is of
// type 'BitmapSurface', we must cast it before we can use it.
BitmapSurface* surface = (BitmapSurface*)view->surface();
// Make sure our surface is not NULL-- it may be NULL if the WebView
// process has crashed.
if (surface != NULL) {
// Save our BitmapSurface to a JPEG image
surface->SaveToJPEG(WSLit("./result.jpg"));
std::cout << "Saved a render of the page to 'result.jpg'." << std::endl;
// Open up the saved JPEG
#if defined(__WIN32__) || defined(_WIN32)
system("start result.jpg");
#elif defined(__APPLE__)
system("open result.jpg");
#endif
}
// Destroy our WebView instance
view->Destroy();
// Update once more before we shutdown for good measure
Update(100);
// Destroy our WebCore instance
WebCore::Shutdown();
return 0;
}
void Update(int sleep_ms) {
// Sleep a specified amount
#if defined(__WIN32__) || defined(_WIN32)
Sleep(sleep_ms);
#elif defined(__APPLE__)
usleep(sleep_ms * 1000);
#endif
// You must call WebCore::update periodically
// during the lifetime of your application.
WebCore::instance()->Update();
}
我尝试以以下方式对其进行编译:
gcc -o main -Wall -I/opt/awesomium_v1.7.2_sdk_linux64/include/Awesomium/ -L/opt/awesomium_v1.7.2_sdk_linux64/bin -lawesomium-1-7 main.cc
但是,我在控制台上获得以下错误输出:
/opt/awesomium_v1.7.2_sdk_linux64/samples/hello# gcc -o main -Wall -I/opt/awesomium_v1.7.2_sdk_linux64/include/Awesomium/ -L/opt/awesomium_v1.7.2_sdk_linux64/bin -lawesomium-1-7 main.cc
main.cc:16:31: error: Awesomium/WebCore.h: No such file or directory
main.cc:17:37: error: Awesomium/BitmapSurface.h: No such file or directory
main.cc:18:34: error: Awesomium/STLHelpers.h: No such file or directory
main.cc:31: error: ‘Awesomium’ is not a namespace-name
main.cc:31: error: expected namespace-name before ‘;’ token
main.cc: In function ‘int main()’:
main.cc:39: error: ‘WebCore’ was not declared in this scope
main.cc:39: error: ‘web_core’ was not declared in this scope
main.cc:39: error: ‘WebCore’ is not a class or namespace
main.cc:39: error: ‘WebConfig’ was not declared in this scope
main.cc:43: error: ‘WebView’ was not declared in this scope
main.cc:43: error: ‘view’ was not declared in this scope
main.cc:46: error: ‘WebURL’ was not declared in this scope
main.cc:46: error: expected ‘;’ before ‘url’
main.cc:47: error: ‘url’ was not declared in this scope
main.cc:65: error: ‘BitmapSurface’ was not declared in this scope
main.cc:65: error: ‘surface’ was not declared in this scope
main.cc:65: error: expected primary-expression before ‘)’ token
main.cc:65: error: expected ‘;’ before ‘view’
main.cc:71: error: ‘WSLit’ was not declared in this scope
main.cc:90: error: ‘WebCore’ is not a class or namespace
main.cc: In function ‘void Update(int)’:
main.cc:105: error: ‘WebCore’ has not been declared
我在做什么错?
您的包含路径似乎是不正确的。尝试用
编译gcc -o main -Wall -I/opt/awesomium_v1.7.2_sdk_linux64/include -L/opt/awesomium_v1.7.2_sdk_linux64/bin -lawesomium-1-7 main.cc
相关文章:
- 显示错误输出的简单数组排序程序
- 简单C++"Hello World"程序的执行时间长
- 而循环:简单的除法程序输出零,不明白为什么
- 为什么一个简单的程序不能立即启动
- 使用简单两相锁定的并发程序
- [[可能]]和[[不太可能]]影响程序汇编的简单示例?
- GDB 8.1 无法在单线程简单程序中跟踪 std::string 变量的值
- 多线程 gtkmm 应用程序最简单的示例
- 我写了一个简单的矢量程序,在其中我得到了以下输出。你能帮我理解它的输出吗?
- 如何使用cmake和Visual Studio 2019编译简单的Windows应用程序?
- 试图解决这个简单的C++程序,但我被困在某个地方
- 我已经安装了用于c++编程的升华3,但在编写了一个简单的程序后,我遇到了以下错误
- 无法编译简单的C++17程序
- 如何设置一个简单的CGAL+Qt程序
- Cmake无法在qt-creater/collect2上编译简单的测试程序:错误:ld
- 令牌之前的简单程序预期标识符'('
- 使用Cmake进行简单的CUDA程序
- 我创建了一个简单的程序,但有些地方不对劲
- 编译简单的多文件类程序时出现未定义的引用错误
- 程序简单,没有调用堆栈,"inpossible"查找错误