Примеры компиляции V8 / hello-world.cc в Ubuntu - PullRequest
0 голосов
/ 03 июня 2018

Попытка скомпилировать V8 samples / hello-world.cc в ubuntu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "include/libplatform/libplatform.h"
#include "include/v8.h"

int main(int argc, char* argv[]) {
  // Initialize V8.
  v8::V8::InitializeICUDefaultLocation(argv[0]);
  v8::V8::InitializeExternalStartupData(argv[0]);
  std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
  v8::V8::InitializePlatform(platform.get());
  v8::V8::Initialize();

  // Create a new Isolate and make it the current one.
  v8::Isolate::CreateParams create_params;
  create_params.array_buffer_allocator =
      v8::ArrayBuffer::Allocator::NewDefaultAllocator();
  v8::Isolate* isolate = v8::Isolate::New(create_params);
  {
    v8::Isolate::Scope isolate_scope(isolate);

    // Create a stack-allocated handle scope.
    v8::HandleScope handle_scope(isolate);

    // Create a new context.
    v8::Local<v8::Context> context = v8::Context::New(isolate);

    // Enter the context for compiling and running the hello world script.
    v8::Context::Scope context_scope(context);

// Create a string containing the JavaScript source code.
    v8::Local<v8::String> source =
        v8::String::NewFromUtf8(isolate, "'Hello' + ', World!'",
                                v8::NewStringType::kNormal)
            .ToLocalChecked();

    // Compile the source code.
    v8::Local<v8::Script> script =
        v8::Script::Compile(context, source).ToLocalChecked();

    // Run the script to get the result.
    v8::Local<v8::Value> result = script->Run(context).ToLocalChecked();

    // Convert the result to an UTF8 string and print it.
    v8::String::Utf8Value utf8(isolate, result);
    printf("%s\n", *utf8);
  }

  // Dispose the isolate and tear down V8.
  isolate->Dispose();
  v8::V8::Dispose();
  v8::V8::ShutdownPlatform();
  delete create_params.array_buffer_allocator;
  return 0;
}

с помощью следующей команды:

g++ -I. -Iinclude samples/hello-world.cc -o hello-world -Wl,--start-group \
out.gn/x64.release/libicui18n.so out.gn/x64.release/libicuuc.so\
out.gn/x64.release/libv8_libbase.so\
out.gn/x64.release/libv8_libplatform.so\ out.gn/x64.release/libv8.so\
out.gn/x64.release/libc++.so\
-Wl,--end-group -lrt -ldl -pthread -std=c++0x

И получение ошибки:

hello-world.cc:(.text+0x75): undefined reference to
v8::platform::NewDefaultPlatform(int, v8::platform::IdleTaskSupport,
v8::platform::InProcessStackDumping,
std::unique_ptr<v8::TracingController,
std::default_delete<v8::TracingController> >)

Обратите внимание, что я построил V8 с аргументами GN:

"is_debug = false, is_official_build = true, is_component_build = true, is_cfi = false, is_clang = false, v8_use_external_startup_data = false, Treat_warnings_as_crors = falseuse_sysroot = false, use_gold = false "

Я что-то не так делаю со встроенной версией V8 или компиляцией примеров / hello-world.cc

1 Ответ

0 голосов
/ 06 июня 2018

В командной строке компилятора попробуйте удалить \ после out.gn/x64.release/libv8_libplatform.so.\ является символом «escape», поэтому он меняет интерпретацию следующего пробела - в частности, он делает его частью имени файла, а не разделителем имени файла, в результате чего имя файла не существует.

Это помогает?

...