tags:

views:

121

answers:

1

Hi,

I'm trying to compile a file with the V8 the JavaScript Engine by Google. I installed scons and have compiled the V8 engine. But, here is where the problem lies, I stay in the V8 directory as they say and make a file named hello_world.cpp with the code:

#include <v8.h>

using namespace v8;

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

      // Create a stack-allocated handle scope.
      HandleScope handle_scope;

      // Create a new context.
      Persistent<Context> context = Context::New();

      // 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.
      Handle<String> source = String::New("'Hello' + ', World!'");

      // Compile the source code.
      Handle<Script> script = Script::Compile(source);

      // Run the script to get the result.
      Handle<Value> result = script->Run();

      // Dispose the persistent context.
      context.Dispose();

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

Then I compile using gcc hello_world.cpp -o libv8.a. But, when I compile it I get a skew of errors:

hello_world.cpp:1:16: error: v8.h: No such file or directory
hello_world.cpp:3: error: ‘v8’ is not a namespace-name
hello_world.cpp:3: error: expected namespace-name before ‘;’ token
hello_world.cpp: In function ‘int main(int, char**)’:
hello_world.cpp:8: error: ‘HandleScope’ was not declared in this scope
hello_world.cpp:8: error: expected `;' before ‘handle_scope’
hello_world.cpp:11: error: ‘Persistent’ was not declared in this scope
hello_world.cpp:11: error: ‘Context’ was not declared in this scope
hello_world.cpp:11: error: ‘context’ was not declared in this scope
hello_world.cpp:11: error: ‘Context’ is not a class or namespace
hello_world.cpp:15: error: ‘Context’ is not a class or namespace
hello_world.cpp:15: error: expected `;' before ‘context_scope’
hello_world.cpp:18: error: ‘Handle’ was not declared in this scope
hello_world.cpp:18: error: ‘String’ was not declared in this scope
hello_world.cpp:18: error: ‘source’ was not declared in this scope
hello_world.cpp:18: error: ‘String’ is not a class or namespace
hello_world.cpp:21: error: ‘Script’ was not declared in this scope
hello_world.cpp:21: error: ‘script’ was not declared in this scope
hello_world.cpp:21: error: ‘Script’ is not a class or namespace
hello_world.cpp:24: error: ‘Value’ was not declared in this scope
hello_world.cpp:24: error: ‘result’ was not declared in this scope
hello_world.cpp:30: error: ‘String’ is not a class or namespace
hello_world.cpp:30: error: expected `;' before ‘ascii’
hello_world.cpp:31: error: ‘ascii’ was not declared in this scope
hello_world.cpp:31: error: ‘printf’ was not declared in this scope

I don't get why it say V8.h is not declared. I already built it and I'm in its directory and I'm guessing if I get rid of that all the other errors will go away. Any suggestions?

+1  A: 

i just believe you in that you are really inside the toplevel source directory (and since i do not have compiled v8 i only believe that libvp8.a is created in that toplevel directory):

% g++ -Iinclude hello_world.cpp -o hello_world libv8.a
  1. it says "v8.h" is not declared because that file is inside the "include" directory and the preprocessor is not able to find it out of thin air.

  2. furthermore: you are compiling a .cpp file with the C compiler instead of the C++ compiler.

  3. you are using the '-o' flag wrong because it defines the name of the linked binary and thus needs a name, you do not want the output binary be named "libvp8.a"

akira
Thanks! 15 char.
thyrgle