2010-06-28 8 views
4

Je suis en train de compiler un fichier avec le moteur JavaScript de Google V8. J'ai installé scons et ai compilé le moteur V8. Mais, voici où réside le problème, je reste dans le répertoire V8 comme ils disent et faire un fichier nommé hello_world.cpp avec le code:Problèmes de compilation V8

#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; 
    } 

Je Compile en utilisant gcc hello_world.cpp -o libv8.a. Mais, quand je le compiler je reçois un biais d'erreurs:

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 

Je ne comprends pas pourquoi il dit V8.h n'est pas déclarée. Je l'ai déjà construit et je suis dans son répertoire et je devine si je me débarrasse de ce que toutes les autres erreurs vont disparaître. Aucune suggestion?

Répondre

3

je crois que vous en ce que vous êtes vraiment à l'intérieur du répertoire source de premier niveau (et depuis que je ne crois pas avoir compilé v8 i seulement libvp8.a est créé dans ce répertoire de premier niveau):

% g++ -Iinclude hello_world.cpp -o hello_world libv8.a 
  1. il est dit que "v8.h" n'est pas déclaré car ce fichier se trouve dans le répertoire "include" et le préprocesseur n'est pas capable de le trouver à partir de rien. En outre, vous compilez un fichier .cpp avec le compilateur C au lieu du compilateur C++.

  2. vous utilisez le « -o » indicateur erroné parce qu'il définit le nom du binaire et doit donc un nom, vous ne voulez pas l'être binaire de sortie nommé lié « libvp8.a »

+0

Merci! 15 caractères –