无法编译简单的C ++程序

时间:2014-01-25 16:24:20

标签: c++ include awesomium

我下载了以下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

我做错了什么?

1 个答案:

答案 0 :(得分: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