在Windows上构建V8不会输出v8_base.lib

问题描述 投票:2回答:1

我想构建V8并将其嵌入C ++程序中,以使用SWIG允许Javascript应用程序调用C ++库。但是,按照构建V8的步骤操作后,我缺少了一些重要的库以链接到V8(例如V8_base.lib):

  1. 获取v8
  2. cd v8
  3. git pull的起源
  4. gclient同步
  5. python工具/dev/v8gen.py x64.release
  6. 忍者-C out.gn/x64.release

我有DEPOT_TOOLS_WIN_TOOLCHAIN = 0且GYP_MSVS_VERSION = 2019。我的args.gn是以下内容(我在有无最后一行的情况下构建):

is_debug = false
target_cpu = "x64"
is_component_build = false
v8_static_library = true
is_clang = false
use_lld = false

在成功构建之后,我发现out.gn \ x64.release \ obj下没有v8_base.lib文件,因为所有文档都表明应该存在。奇怪的是,我看到一个v8.stamp和v8_base.stamp文件,但是没有相应的* .lib。我想念什么?不再需要将这些库嵌入到C ++程序中吗?

v8 embedded-v8
1个回答
0
投票

概述

[The instructions on the website to build a sample app比您现在遵循的说明要好一些]

v8_base.a目标已于2019年4月从build.gn文件here中删除

先决条件

  1. Python2
  2. Git
  3. Ninja
  4. G ++

更新了构建v8的说明(在Linux / macos上)

这里是我今天成功编译和运行v8的步骤

  1. 安装Google的软件仓库工具:git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" ./depot_tools
  2. 下载v8:fetch v8fetch --no-history v8
  3. 移至v8目录cd v8
  4. (可能为您的系统生成一个发行版:tools/dev/v8gen.py x64.release
  5. 编辑out.gn/x64.release/args.gn以包含以下文本:
is_debug = false
target_cpu = "x64"
use_custom_libcxx = false
v8_monolithic = true
v8_use_external_startup_data = false
  1. 生成忍者构建文件gn gen out.gn/x64.release
  2. Build v8(慢)ninja -C out.gn/x64.release

使用新创建的v8库

在项目目录的根目录中创建一个名为src的文件夹,并在该文件夹中创建一个新文件main.cc,如下所示:

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

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

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

  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);
    v8::HandleScope handle_scope(isolate); // Create a stack-allocated handle scope.
    v8::Local<v8::Context> context = v8::Context::New(isolate); // Create a new context.
    v8::Context::Scope context_scope(context); // Enter the context for compiling and running the hello world script.

    {
      v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, "Object.keys({ h: 1, e: 2, ll: 3, o: 4, _: 5, w: 6, or: 7, l: 8, d: 9 })", v8::NewStringType::kNormal).ToLocalChecked(); // Create a string containing the JavaScript source code.
      v8::Local<v8::Script> script = v8::Script::Compile(context, source).ToLocalChecked(); // Compile the source code.
      v8::Local<v8::Value> result = script->Run(context).ToLocalChecked(); // Run the script to get the result.
      v8::String::Utf8Value utf8(isolate, result); // Convert the result to an UTF8 string and print it.
      printf("%s\n", *utf8);
    }
  }

  isolate->Dispose();
  v8::V8::Dispose();
  v8::V8::ShutdownPlatform();
  delete create_params.array_buffer_allocator;
  return 0;
}
  1. 使用在忍者版本中创建的新的整体库来构建源代码:g++ -Iv8 -Iv8/include src/main.cc -o bin/my_program -lv8_monolith -Lv8/out.gn/x64.release.sample/obj/ -pthread -std=c++0x

为此,您的文件结构应类似于

depot_tools
v8
src/main.cc

它将在您的bin文件夹中创建一个名为my_program的新可执行文件,您可以直接执行./bin/my_program

© www.soinside.com 2019 - 2024. All rights reserved.