如何在不同的c ++项目中使用Google V8引擎? [英] How do I use the Google V8 Engine in a different c++ Project?

查看:1586
本文介绍了如何在不同的c ++项目中使用Google V8引擎?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在Google V8引擎中导入 .lib .h 文件,



我需要导入任何名称的文件吗?



v8 的来源是编译和构建时,




  • cctest

  • fuzzer_support

  • 生成bytecode-期望

  • gmock

  • / li>
  • icui18n

  • icuuc

  • inspector_protocol

  • json_fuzzer_lib

  • mbnapshot

  • parse_fuzzer_lib

  • regexp_fuzzer_lib

  • unittests

  • v8

  • v8_base_0

  • v8_base_1

  • v8_base_2

  • v8_base_3

  • v8_external_snapshot

  • v8_libbase

  • v8_libplatform

  • v8_libsampler

  • v8_nosnapshot

  • v8_simple_json_fuzzer

  • v8_simple_parser_fuzzer

  • v8_simple_regexp_fuzzer

  • v8_simple_wasm_asmjs_fuzzer

  • v8_simple_wasm_fuzzer

  • wasm_fuzzer_lib

  • wasm_asmjs_fuzzer_lib



生成名称文件。



c> v8 ,并输出 javascript 的运行值。



我的猜测,似乎只使用 v8.lib v8_base(0,1,2,3).lib v8.h



是一个新的c ++项目中的示例代码, hello-world.cc ,做了一个cpp文件。我运行 LNK2019 LNK1120 错误。


1> -----构建开始:项目:v8Application,配置:调试Win32 -----

1> v8Application.cpp

1> v8Application.obj:error LNK2019:在函数class v8 :: Platform * __cdecl v8 :: platform :: CreateDefaultPlatform(int)中引用的未解析的外部符号_main(?CreateDefaultPlatform @ platform @ v8 @@ YAPAVPlatform @ 2 @ H @ Z)1> c:\users\kito\documents\visual studio 2015 \Projects\v8Application\Debug\v8Application.exe:致命错误LNK1120:1未解析的外部

========== Build:0成功,1失败,0最新,0跳过==========

blockquote>

似乎不能定义platform :: CreateDefaultPlatform部分只在libplatform.h声明。
然而,我会添加src \ libplatform \ default-platform.ccplatform :: CreateDefaultPlatform已经定义,其他错误发生在add。



Ws2_32.lib winmm.lib 也被添加到Additional Dependencies属性的项目。



如何做到这一点?

解决方案

项目,然后LINK与V8,但您不得将V8的源文件添加到您的项目。



首先要做的是编译V8并记录生成库的位置(或将它们复制到您选择的目录)。这同样适用于V8的包含文件,它们必须可用,才能包含在您的项目中(不建议将它们复制到您的项目目录中)。



您的控制台项目的设置转到 Linker - >输入 - >附加依赖关系并放置 v8.lib 。如果错误仍然存​​在,您可能需要添加 v8_libplatform.lib



包含文件,在你的项目设置中,你应该去 C / C ++ - >一般 - >



但是请记住,您必须首先编译v8并将lib和include目录公开到您的



您的项目文件表明您已配置了您的新项目。



项目配置:


$ b项目仅适用于配置Release,但以上输出表示您正在以调试模式进行编译。 $ b

 < ItemDefinitionGroup Condition ='$(Configuration)| $(Platform)'=='Release | Win32'> 
...
< Link>
< AdditionalDependencies> ws2_32.lib; winmm.lib; v8.lib; v8_base_0.lib; v8_base_1.lib ...
< / Link>
< ItemDefinitionGroup

上面的编译器输出:

  1> -----开始:项目:v8Application,配置:调试Win32 ----- 
pre>

您必须为所有配置配置项目,或至少使用您设置的配置进行测试。



另一方面, v8_libplatform.lib 不在附加依赖项列表中,您可以添加它。


If I import the .lib and .h files in the Google V8 Engine, it will attempt to use them in a different c ++ project.

Do I need to import a file of any name?

When the source of the v8 was compile and build,

  • cctest
  • fuzzer_support
  • generate-bytecode-expectations
  • gmock
  • gtest
  • icui18n
  • icuuc
  • inspector_protocol
  • json_fuzzer_lib
  • mksnapshot
  • parser_fuzzer_lib
  • regexp_fuzzer_lib
  • unittests
  • v8
  • v8_base_0
  • v8_base_1
  • v8_base_2
  • v8_base_3
  • v8_external_snapshot
  • v8_libbase
  • v8_libplatform
  • v8_libsampler
  • v8_nosnapshot
  • v8_simple_json_fuzzer
  • v8_simple_parser_fuzzer
  • v8_simple_regexp_fuzzer
  • v8_simple_wasm_asmjs_fuzzer
  • v8_simple_wasm_fuzzer
  • wasm_fuzzer_lib
  • wasm_asmjs_fuzzer_lib

name file is generated.

I simply use the v8, and it outputs a run value of javascript.

My guess, seems to use only "v8.lib, v8_base (0,1,2,3) .lib" and "v8.h".

Is the sample code in a new c ++ project by copying the contents of the "hello-world.cc", made a cpp file. And I run, "LNK2019", "LNK1120" error occurs.

1>----- Build started: Project: v8Application, Configuration: Debug Win32 -----
1> v8Application.cpp
1>v8Application.obj : error LNK2019: unresolved external symbol _main referenced in function"class v8::Platform * __cdecl v8::platform::CreateDefaultPlatform(int)" (?CreateDefaultPlatform@platform@v8@@YAPAVPlatform@2@H@Z) 1>c:\users\kito\documents\visual studio 2015\Projects\v8Application\Debug\v8Application.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

It seems must not defined "platform :: CreateDefaultPlatform" part is turned only in 'libplatform.h' declaration. However, I would add "src \ libplatform \ default-platform.cc" the platform :: CreateDefaultPlatform has been defined, other error occurs in the add.

"Ws2_32.lib, winmm.lib" was also added to the project of the Additional Dependencies property.

How do I do this?

解决方案

You must create your project and then LINK with V8, but you must not add V8's source files to your project.

The first thing to do is to compile V8 and take note of where the libraries were generated (or copy them to the directory of your choice). The same applies to V8's include files, they must be available in order to be included in your project (it is not advisable to copy them to your project directory).

In your console project's settings go to Linker -> Input -> Additional Dependencies and put v8.lib there. If the error is still present work you might want to add v8_libplatform.lib too.

Something similar applies to the include files, in your project settings you should go to C/C++ -> General -> Additional Include Directories and add V8's include directory there.

But remember, you must first compile v8 alone and expose the lib and include directories to your new project.

Update:

Your project file indicates that you configured Your project only for the configuración "Release", but the output above indicates that you are compiling in Debug mode.

Project config:

<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    ...
    <Link>
        <AdditionalDependencies>ws2_32.lib;winmm.lib;v8.lib;v8_base_0.lib;v8_base_1.lib...
    </Link>
<ItemDefinitionGroup

Compiler output above:

1>----- Build started: Project: v8Application, Configuration: Debug Win32 -----

You must configure your project for all configurations, or at least test it using the configuration you've setup.

On the other hand, v8_libplatform.lib is not in the list of additional dependencies, you may want to add it.

这篇关于如何在不同的c ++项目中使用Google V8引擎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆