2014-01-25 130 views
1

我下载了以下C++库(商业模拟浏览器)http://wiki.awesomium.com/。我打开它,目录结构如下所示:无法编译简单的C++程序

/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 

我在做什么错?

回答

0

您的包含路径似乎不正确。尝试编译

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 
+0

Thx!但现在我得到:/opt/awesomium_v1.7.2_sdk_linux64/samples/hello#的gcc -o主-Wall -I /选择/ awesomium_v1.7.2_sdk_linux64 /包括/ -L /选择/ awesomium_v1.7.2_sdk_linux64/bin中-lawesomium-1 -7 main.cc 在/ usr /斌/劳工处:找不到-lawesomium-1-7 collect2:LD返回1退出状态 – toom

+0

再有就是你的'-l'和'-L'之间有一些不匹配。图书馆是否没有编辑说明?对于一个商业的人会这样想。 – fredrik