问题
I successfully compiled v8 javascript engine (on windows) ; now I try to follow the Getting started article but I am stuck at this point:
- Compile hello_world.cpp, linking to the static libraries created in the build process.
The example is for linux (and probably for an earlier version).
I tried to link against all libraries that I could without success:
User@PC:/cygdrive/c/Users/Yvain/Documents/depot_tools/v8/build/Release
g++ -std=c++0x -I"C:\Users\Yvain\Documents\depot_tools\v8" -Llib -lv8_libbase -lv8_base_0 -lv8_base_1 -lv8_base_2 -lv8_base_3 -lgmock -lgtest -licui18n -licuuc -lv8_external_snapshot -lv8_libplatform -lv8_nosnapshot hello_world.cpp -o hello_world
It gives the following errors:
/tmp/ccPxkjlV.o:hello_world.cpp:(.text+0x1a):
undefined reference to « v8::V8::InitializeICU(char const*) »
[...]undefined reference to « v8::V8::InitializeExternalStartupData(char const*) »
[...]
[...]undefined reference to « v8::Isolate::Exit() »
There is a working example: v8/sample/hello-world.vcxproj
but I don't understand where the libraries are specified in the project.
回答1:
Visual Studio project v8/sample/hello-world.vcxproj
has been generated with GYP from v8/build/samples/samples.gyp
with all necessary dependencies.
In the current version of "Getting started" article, in "Run example" section, item list #3 contains an example of command line to build the hello_world:
Compile hello_world.cpp, linking to the static libraries created in the build process. For example, on 64bit Linux using the GNU compiler:
g++ -I. hello_world.cpp -o hello_world -Wl,--start-group out/x64.release/obj.target/{tools/gyp/libv8_{base,libbase,external_snapshot,libplatform},third_party/icu/libicu{uc,i18n,data}}.a -Wl,--end-group -lrt -ldl -pthread -std=c++0x
On Windows you need to use the similar list of static libraries as a linker input. Please note these static libraries are placed in v8/build/Release/lib
directory.
来源:https://stackoverflow.com/questions/32336298/how-to-link-against-v8