How to use v8 built as shared library on Windows using MSVC?

685 views
Skip to first unread message

deadmorous

unread,
Nov 4, 2015, 7:17:32 AM11/4/15
to v8-users
Hello everyone,

I need to use v8 as shared library in both linux (gcc) and Windows (msvc). Previously (e.g. v8 version 3.28) I can manage that by specifying component=shared_library as an argument to make in linux,
and -Dcomponent=shared_library as an argument to build\gyp_v8 in Windows. To use libv8.so (linux) I linked against it, and to use v8.dll (Windows) I linked against the v8.lib import library.
Notice that in the past, the following v8 initialization code was sufficient:

V8::Initialize();
Isolate::New()->Enter();

Now things have changed. I'm trying to upgrade to v8 4.8.99, particularly commit 961fef2dd2852db5165de3dbdbd13162792448fe (30.10.2015 05:57:23 2015 -0700).
The initialization code now involves the following:

V8::InitializeICU();
V8
::InitializeExternalStartupData(argv[0]);
Platform* platform = platform::CreateDefaultPlatform();
V8
::InitializePlatform(platform);
V8
::Initialize();

plus more complicated Isolate instance creation, as described here.

If I only link against v8, the linker complains that platform::CreateDefaultPlatform() is an undefined reference. Therefore, I need to link against v8_libplatform, too, which is a static library.
When I do so in Linux, everything works well, provided I disable snapshots (snapshot=off) in v8 build.
In Windows, however, this does not work. The problem is that the source code of v8_libplatform refers to V8_Fatal() that is implemented in v8 (file src/base/logging.cc) but not exported.

Therefore, linking to v8_libplatform.lib fails.

My question is as follows:
How should I build and use v8 shared library on Windows using Microsoft Visual Studio?

Best regards,
Stepan Orlov

deadmorous

unread,
Nov 4, 2015, 8:30:16 AM11/4/15
to v8-users
Current version tag is actually 4.8.220, not 4.8.99, sorry

deadmorous

unread,
Nov 6, 2015, 4:54:35 PM11/6/15
to v8-users
The solution is to also link v8_libplatform.lib static library, as follows from the Hello World example :)

Zac Hansen

unread,
Apr 29, 2016, 8:22:36 AM4/29/16
to v8-users
I'm running into a similar problem in OS X.   and just adding libplatform isn't enough.   You also have to statically link v8_libbase as well in order to link a new .dylib from v8 shared libs.

Can anyone lend any insight as to why everything can't be built into dynamic libraries and why some static libs are still required?

--Zac

my cmake-generated link line for building a .dylib: 


 

/usr/local/Cellar/cmake/3.4.3/bin/cmake -E cmake_link_script CMakeFiles/v8toolkit_shared.dir/link.txt --verbose=1

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++  -fsanitize=address -g -dynamiclib -Wl,-headerpad_max_install_names  -o libv8toolkit.dylib -install_name @rpath/libv8toolkit.dylib CMakeFiles/v8toolkit_shared.dir/javascript.cpp.o CMakeFiles/v8toolkit_shared.dir/v8helpers.cpp.o CMakeFiles/v8toolkit_shared.dir/v8toolkit.cpp.o  -L/Users/xaxxon/v8libs/x64.debug.shared   -licui18n -licuuc -lv8 -lv8_libplatform -lv8_libbase -lcppformat -Wl,-rpath,/Users/xaxxon/v8libs/x64.debug.shared





Reply all
Reply to author
Forward
0 new messages