Search code examples
javascriptc++v8embedded-v8

How do I use the Google V8 Engine in a different c++ Project?


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?


Solution

  • 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.