I have compiled v8 on Ubuntu and am now trying to get the sample
hello-world.cpp working, however, when I execute it I get a Segmentation
fault. Here is my source code:
#include "include/v8.h"
#include "include/libplatform/libplatform.h"
using namespace v8;
int main(int argc, char* argv[]) {
// Initialize V8.
V8::InitializeICU();
//V8::Initialize();
Platform* platform = platform::CreateDefaultPlatform();
V8::InitializePlatform(platform);
V8::Initialize();
// Create a new Isolate and make it the current one.
Isolate* isolate = Isolate::New();
{
Isolate::Scope isolate_scope(isolate);
// Create a stack-allocated handle scope.
HandleScope handle_scope(isolate);
// Create a new context.
Local<Context> context = Context::New(isolate);
// Enter the 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::NewFromUtf8(isolate, "'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 UTF8 string and print it.
String::Utf8Value utf8(result);
printf("%s\n", *utf8);
}
// Dispose the isolate and tear down V8.
isolate->Dispose();
V8::Dispose();
V8::ShutdownPlatform();
delete platform;
return 0;
}
To compile, I use the following command:
g++ -I. hello_world.cpp -o hello_world -Wl,--start-group out/native/obj.
target/{tools/gyp/libv8_{base,libbase,snapshot,libplatform},third_party/icu/
libicu{uc,i18n,data}}.a -Wl,--end-group -lrt -ldl -pthread -std=c++0x
To run, I use
./hello_world
I have just started using v8 and I am unable to figure out the error.
However, when I run this piece of code, it runs fjust fine.
#include "include/v8.h"
#include "include/libplatform/libplatform.h"
using namespace v8;
int main(int argc, char* argv[]) {
// Get the default Isolate created at startup.
V8::Initialize();
Isolate* isolate = Isolate::GetCurrent();
if(!isolate) {
isolate = v8::Isolate::New();
isolate->Enter();
}
// Create a stack-allocated handle scope.
HandleScope handle_scope(isolate);
return 0;
}
Any help would be appreciated. Thanks!
--
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.