Many Erros When I Try Compile C++ In V8 - Javascript
I try using: git clone git://github.com/v8/v8.git v8 && cd v8 or svn checkout http://v8.googlecode.com/svn/trunk/ v8 Use libs: make dependencies sudo apt-get install apt-
Solution 1:
Based on the answer from @Sim, here is the working version.
#include "v8.h"
using namespacev8;
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);
return0;
}
To compile and run it, assume you have v8 headers files in ../include
and v8 libraries in ../lib
g++ -L../lib -I../include hello.cc -o a.out -lv8_base.x64 -lv8_snapshot -lpthread && ./a.out
Solution 2:
The C++ code you are trying to compile is partial example ("pseudo code") taken from the V8 "Getting Started" guide. It can't work as it is. What you need to get this running is illustrated in the same document below:
- Include v8.h header and link your project to the static (or shared) V8 library.
- Import v8 namespace (
using namespace v8
); - Get a reference/pointer to the default Isolate (
Isolate::GetCurrent()
). - Create a HandleScope for local handles.
- Create and enter the V8 execution context.
- And only then you can use something like the code above.
Refer to the V8 Getting Started Guide for details.
Post a Comment for "Many Erros When I Try Compile C++ In V8 - Javascript"