Problems compiling V8

I am trying to compile a file with Google's V8 JavaScript Engine. I installed scons and compiled the V8 engine. But the problem here is that I remain in the V8 directory, as they say, and create a file called 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 with gcc hello_world.cpp -o libv8.a . But when I compile it, I get a skew error:

 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 do not understand why he says that V8.h is not announced. I have already built it, and I am in its directory, and I assume that if I get rid of this, all other errors will disappear. Any suggestions?

+4
source share
1 answer

I just believe that you really are in the toplevel source directory (and since I did not compile v8, I believe libvp8.a is created in this top level directory):

 % g++ -Iinclude hello_world.cpp -o hello_world libv8.a 
  • he says that "v8.h" is not declared because this file is inside the "include" directory and the preprocessor cannot find it from the air.

  • Also: you are compiling a .cpp file with a C compiler instead of a C ++ compiler.

  • you use the "-o" flag incorrectly because it defines the name of the associated binary and therefore needs a name; you do not want the output binary to be called "libvp8.a"

+3
source

Source: https://habr.com/ru/post/1314094/


All Articles