4

GoogleのJavaScriptエンジンV8でファイルをコンパイルしようとしています。V8エンジンをインストールsconsしてコンパイルしました。しかし、ここに問題があります。彼らが言うように、私はV8ディレクトリにとどまりhello_world.cpp、コードで名前が付けられたファイルを作成します。

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

次に、を使用してコンパイルしgcc hello_world.cpp -o libv8.aます。しかし、それをコンパイルすると、エラーのスキューが発生します。

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

V8.hが宣言されていないという理由がわかりません。私はすでにそれを構築し、そのディレクトリにいます。それを取り除くと、他のすべてのエラーがなくなると思います。助言がありますか?

4

1 に答える 1

3

私はあなたが本当にトップレベルのソースディレクトリ内にいると信じています(そして私はv8をコンパイルしていないので、libvp8.aがそのトップレベルディレクトリに作成されていると信じています):

% g++ -Iinclude hello_world.cpp -o hello_world libv8.a
  1. 「v8.h」は宣言されていません。これは、そのファイルが「include」ディレクトリ内にあり、プリプロセッサがそれを空中から見つけることができないためです。

  2. さらに、C++コンパイラではなくCコンパイラを使用して.cppファイルをコンパイルしています。

  3. リンクされたバイナリの名前を定義し、名前が必要なため、「-o」フラグを間違って使用しています。出力バイナリに「libvp8.a」という名前を付けたくない場合

于 2010-06-28T17:41:55.033 に答える