0

我正在尝试为 V8 编译 hello world 示例,但我一直遇到编译时错误。这是代码:

#include <v8/src/v8.h>

using namespace v8;

int main(int argc, char* argv[]) {

  // Create a string holding the JavaScript source code.
  String source = String::New("Hi");

  // Compile it.
  Script script = Script::Compile(source) ;

  // Run it.
  Value result = script->Run();

  // Convert the result to an ASCII string and display it.
  String::AsciiValue ascii(result) ;
  printf("%s\n", *ascii) ;
  return 0;
}

这是编译错误:

error: conversion from ‘v8::Local<v8::String>’ to non-scalar type ‘v8::String’ requested

错误出现在第 8 行,它说: String source = String::New("Hi");

我试过用谷歌搜索这个错误,但似乎找不到有意义的修复方法。有任何想法吗?

我都试过了:

svn 结帐http://v8.googlecode.com/svn/trunk/ v8

svn 结帐http://v8.googlecode.com/svn/branches/bleeding_edge/ v8

并为两者获得相同的错误。

4

2 回答 2

1

根据错误消息,尝试:

Local<String> source = String::New("Hi");
于 2012-07-02T04:05:41.450 回答
0

试试这个代码:

HandleScope handle_scope;
Persistent<Context> context = Context::New();
Context::Scope context_scope(context);
Handle<String> source = String::New("'Hello' + ', World!'");
Handle<Script> script = Script::Compile(source);
TryCatch trycatch;
Handle<Value> result = script->Run();   
if ( result.IsEmpty() ) {
    Handle<Value> excep = trycatch.Exception();
    String::AsciiValue excep_str(excep);
    printf("%s\n",*excep);
}  else {
    String::AsciiValue ascii(result);
    printf("%s\n", *ascii);
}
context.Dispose();
return 0;
于 2012-07-04T08:54:21.823 回答