当我尝试编译c++;在V8-JavaScript中

当我尝试编译c++;在V8-JavaScript中,javascript,v8,Javascript,V8,我尝试使用: git clone git://github.com/v8/v8.git v8 && cd v8 or svn checkout http://v8.googlecode.com/svn/trunk/ v8 使用LIB: make dependencies sudo apt-get install apt-file; sudo apt-get install libc6-dev-i368 lib32stdc++6; 当我尝试编译一个简单的文件时,如下所示: 命

我尝试使用:

git clone git://github.com/v8/v8.git v8 && cd v8 or svn checkout http://v8.googlecode.com/svn/trunk/ v8 
使用LIB:

make dependencies
sudo apt-get install apt-file;
sudo apt-get install libc6-dev-i368 lib32stdc++6;
当我尝试编译一个简单的文件时,如下所示:

命令使用:

g++ test.cpp -Ideps/v8/include -Ldeps/v8/ -lv8 -lpthread
我得到以下错误输出:

v8/src/

test.cpp: Na função ‘int main(int, char**)’:
test.cpp:4:3: error: ‘String’ was not declared in this scope
test.cpp:4:10: error: expected ‘;’ before ‘source’
test.cpp:7:3: error: ‘Script’ was not declared in this scope
test.cpp:7:10: error: expected ‘;’ before ‘script’
test.cpp:10:3: error: ‘Value’ was not declared in this scope
test.cpp:10:9: error: expected ‘;’ before ‘result’
test.cpp:13:3: error: ‘String’ is not a class or namespace
test.cpp:13:22: error: expected ‘;’ before ‘ascii’
test.cpp:14:19: error: ‘ascii’ was not declared in this scope
test.cpp:14:24: error: ‘printf’ was not declared in this scope

问题是什么?有人能指出我的正确方向吗?< /P> < P>你试图编译的C++代码是从V8“入门”指南中获取的部分示例(“伪代码”)。它不能像现在这样工作。以下同一文档中说明了运行此功能所需的内容:

  • 包含v8.h头并将项目链接到静态(或共享)v8库
  • 导入v8命名空间(
    使用命名空间v8
  • 获取默认隔离的引用/指针(
    Isolate::GetCurrent()
  • 为本地控制柄创建控制柄范围
  • 创建并输入V8执行上下文
  • 只有这样你才能使用上面的代码

  • 有关详细信息,请参阅。

    根据@Sim的回答,以下是工作版本

    #include "v8.h"
    using namespace v8;
    
    
    int main(int argc, char* argv[]) 
    {
    
      // Get the default Isolate created at startup.
      Isolate* isolate = Isolate::GetCurrent();
    
      // Create a stack-allocated handle scope.
      HandleScope handle_scope(isolate);
    
      // Create a new context.
      Handle<Context> context = Context::New(isolate);
    
      // Here's how you could create a Persistent handle to the context, if needed.
      Persistent<Context> persistent_context(isolate, context);
    
      // Enter the created context for compiling and
      // running the hello world script. 
      Context::Scope context_scope(context);
    
      // Create a string containing the JavaScript source code.
      Local<String> source = String::New("'Hello' + ', World'");
    
      // Compile the source code.
      Local<Script> script = Script::Compile(source);
    
      // Run the script to get the result.
      Local<Value> result = script->Run();
    
      // Convert the result to an ASCII string and print it.
      String::AsciiValue ascii(result);
      printf("%s\n", *ascii);
      return 0;
    }
    
    #include "v8.h"
    using namespace v8;
    
    
    int main(int argc, char* argv[]) 
    {
    
      // Get the default Isolate created at startup.
      Isolate* isolate = Isolate::GetCurrent();
    
      // Create a stack-allocated handle scope.
      HandleScope handle_scope(isolate);
    
      // Create a new context.
      Handle<Context> context = Context::New(isolate);
    
      // Here's how you could create a Persistent handle to the context, if needed.
      Persistent<Context> persistent_context(isolate, context);
    
      // Enter the created context for compiling and
      // running the hello world script. 
      Context::Scope context_scope(context);
    
      // Create a string containing the JavaScript source code.
      Local<String> source = String::New("'Hello' + ', World'");
    
      // Compile the source code.
      Local<Script> script = Script::Compile(source);
    
      // Run the script to get the result.
      Local<Value> result = script->Run();
    
      // Convert the result to an ASCII string and print it.
      String::AsciiValue ascii(result);
      printf("%s\n", *ascii);
      return 0;
    }
    
    g++ -L../lib -I../include hello.cc -o a.out -lv8_base.x64 -lv8_snapshot -lpthread && ./a.out