C++ V8 Embedding project structure
I'm trying to get chrome V8 embedded in my C++ project, and I can only get what I could call, my project being embedded in V8. My only concern with this is that my program is cross-platform and I would like build commands to be the same. I started development it on Windows, but I'm using a mac now to get V8 running.
I can get V8 built and their samples running using this setup:
Get this: https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up
get source: https://v8.dev/docs/source-code
build: https://v8.dev/docs/build
My current solution has a few commands install
, build
, run
. The build command is more complicated as it attempts to automatically edit the BUILD.gn
file in V8 to insert your project instead of V8. It will add all files in your source directory to the sources.
This approach feels very wrong for a few reasons. The first being that there is almost definitely a better way to configure my project than editing a build script with a python script. Secondly, I would like V8 to be embedded in my project, not the other way around. I only have SDL2 as a dependency but I have cross platform CMake builds setup, which would be abandoned for however V8 builds the source files. I feel this way could get hard to manage if I add more dependencies.
I'm currently working with a small test project with one source file.
EDIT: I can't find anything on embedding V8 between running a sample and API usage
c++

add a comment |
I'm trying to get chrome V8 embedded in my C++ project, and I can only get what I could call, my project being embedded in V8. My only concern with this is that my program is cross-platform and I would like build commands to be the same. I started development it on Windows, but I'm using a mac now to get V8 running.
I can get V8 built and their samples running using this setup:
Get this: https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up
get source: https://v8.dev/docs/source-code
build: https://v8.dev/docs/build
My current solution has a few commands install
, build
, run
. The build command is more complicated as it attempts to automatically edit the BUILD.gn
file in V8 to insert your project instead of V8. It will add all files in your source directory to the sources.
This approach feels very wrong for a few reasons. The first being that there is almost definitely a better way to configure my project than editing a build script with a python script. Secondly, I would like V8 to be embedded in my project, not the other way around. I only have SDL2 as a dependency but I have cross platform CMake builds setup, which would be abandoned for however V8 builds the source files. I feel this way could get hard to manage if I add more dependencies.
I'm currently working with a small test project with one source file.
EDIT: I can't find anything on embedding V8 between running a sample and API usage
c++

It would probably be a good idea to make an adapter for v8 and sdl build systems incapsulating their build process details and exposing desired build interface.
– VTT
Nov 19 '18 at 16:51
@VTT I'm not sure exactly how the V8 build system is supposed to be used. They have a custom build scripting language (gm or gn, I'm not sure) which I don't think is required to learn (all of it) to use this project. As far as I can tell, the main way is the way I'm using it but it seems very wrong and I can't find anything telling me otherwise
– c_mcg
Nov 19 '18 at 17:05
Yeah, they have that weird GN system now, but you don't need to switch your project to use that build system. Just make an adapter so you can deal with your own and third-party projects in the uniform manner.
– VTT
Nov 19 '18 at 17:13
@VTT Okay, my project is actually split into a dynamic library (which includes SDL) and a (small) executable that includes that dynamic library. I could build the runtime as I have been and add my library as a dependency in their build system which sounds like it might work. Thanks for the help!
– c_mcg
Nov 19 '18 at 17:24
add a comment |
I'm trying to get chrome V8 embedded in my C++ project, and I can only get what I could call, my project being embedded in V8. My only concern with this is that my program is cross-platform and I would like build commands to be the same. I started development it on Windows, but I'm using a mac now to get V8 running.
I can get V8 built and their samples running using this setup:
Get this: https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up
get source: https://v8.dev/docs/source-code
build: https://v8.dev/docs/build
My current solution has a few commands install
, build
, run
. The build command is more complicated as it attempts to automatically edit the BUILD.gn
file in V8 to insert your project instead of V8. It will add all files in your source directory to the sources.
This approach feels very wrong for a few reasons. The first being that there is almost definitely a better way to configure my project than editing a build script with a python script. Secondly, I would like V8 to be embedded in my project, not the other way around. I only have SDL2 as a dependency but I have cross platform CMake builds setup, which would be abandoned for however V8 builds the source files. I feel this way could get hard to manage if I add more dependencies.
I'm currently working with a small test project with one source file.
EDIT: I can't find anything on embedding V8 between running a sample and API usage
c++

I'm trying to get chrome V8 embedded in my C++ project, and I can only get what I could call, my project being embedded in V8. My only concern with this is that my program is cross-platform and I would like build commands to be the same. I started development it on Windows, but I'm using a mac now to get V8 running.
I can get V8 built and their samples running using this setup:
Get this: https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up
get source: https://v8.dev/docs/source-code
build: https://v8.dev/docs/build
My current solution has a few commands install
, build
, run
. The build command is more complicated as it attempts to automatically edit the BUILD.gn
file in V8 to insert your project instead of V8. It will add all files in your source directory to the sources.
This approach feels very wrong for a few reasons. The first being that there is almost definitely a better way to configure my project than editing a build script with a python script. Secondly, I would like V8 to be embedded in my project, not the other way around. I only have SDL2 as a dependency but I have cross platform CMake builds setup, which would be abandoned for however V8 builds the source files. I feel this way could get hard to manage if I add more dependencies.
I'm currently working with a small test project with one source file.
EDIT: I can't find anything on embedding V8 between running a sample and API usage
c++

c++

asked Nov 19 '18 at 16:40
c_mcg
112
112
It would probably be a good idea to make an adapter for v8 and sdl build systems incapsulating their build process details and exposing desired build interface.
– VTT
Nov 19 '18 at 16:51
@VTT I'm not sure exactly how the V8 build system is supposed to be used. They have a custom build scripting language (gm or gn, I'm not sure) which I don't think is required to learn (all of it) to use this project. As far as I can tell, the main way is the way I'm using it but it seems very wrong and I can't find anything telling me otherwise
– c_mcg
Nov 19 '18 at 17:05
Yeah, they have that weird GN system now, but you don't need to switch your project to use that build system. Just make an adapter so you can deal with your own and third-party projects in the uniform manner.
– VTT
Nov 19 '18 at 17:13
@VTT Okay, my project is actually split into a dynamic library (which includes SDL) and a (small) executable that includes that dynamic library. I could build the runtime as I have been and add my library as a dependency in their build system which sounds like it might work. Thanks for the help!
– c_mcg
Nov 19 '18 at 17:24
add a comment |
It would probably be a good idea to make an adapter for v8 and sdl build systems incapsulating their build process details and exposing desired build interface.
– VTT
Nov 19 '18 at 16:51
@VTT I'm not sure exactly how the V8 build system is supposed to be used. They have a custom build scripting language (gm or gn, I'm not sure) which I don't think is required to learn (all of it) to use this project. As far as I can tell, the main way is the way I'm using it but it seems very wrong and I can't find anything telling me otherwise
– c_mcg
Nov 19 '18 at 17:05
Yeah, they have that weird GN system now, but you don't need to switch your project to use that build system. Just make an adapter so you can deal with your own and third-party projects in the uniform manner.
– VTT
Nov 19 '18 at 17:13
@VTT Okay, my project is actually split into a dynamic library (which includes SDL) and a (small) executable that includes that dynamic library. I could build the runtime as I have been and add my library as a dependency in their build system which sounds like it might work. Thanks for the help!
– c_mcg
Nov 19 '18 at 17:24
It would probably be a good idea to make an adapter for v8 and sdl build systems incapsulating their build process details and exposing desired build interface.
– VTT
Nov 19 '18 at 16:51
It would probably be a good idea to make an adapter for v8 and sdl build systems incapsulating their build process details and exposing desired build interface.
– VTT
Nov 19 '18 at 16:51
@VTT I'm not sure exactly how the V8 build system is supposed to be used. They have a custom build scripting language (gm or gn, I'm not sure) which I don't think is required to learn (all of it) to use this project. As far as I can tell, the main way is the way I'm using it but it seems very wrong and I can't find anything telling me otherwise
– c_mcg
Nov 19 '18 at 17:05
@VTT I'm not sure exactly how the V8 build system is supposed to be used. They have a custom build scripting language (gm or gn, I'm not sure) which I don't think is required to learn (all of it) to use this project. As far as I can tell, the main way is the way I'm using it but it seems very wrong and I can't find anything telling me otherwise
– c_mcg
Nov 19 '18 at 17:05
Yeah, they have that weird GN system now, but you don't need to switch your project to use that build system. Just make an adapter so you can deal with your own and third-party projects in the uniform manner.
– VTT
Nov 19 '18 at 17:13
Yeah, they have that weird GN system now, but you don't need to switch your project to use that build system. Just make an adapter so you can deal with your own and third-party projects in the uniform manner.
– VTT
Nov 19 '18 at 17:13
@VTT Okay, my project is actually split into a dynamic library (which includes SDL) and a (small) executable that includes that dynamic library. I could build the runtime as I have been and add my library as a dependency in their build system which sounds like it might work. Thanks for the help!
– c_mcg
Nov 19 '18 at 17:24
@VTT Okay, my project is actually split into a dynamic library (which includes SDL) and a (small) executable that includes that dynamic library. I could build the runtime as I have been and add my library as a dependency in their build system which sounds like it might work. Thanks for the help!
– c_mcg
Nov 19 '18 at 17:24
add a comment |
2 Answers
2
active
oldest
votes
I got V8 building with CMake very easily using brew:
brew install v8
then add the following lines to CMakeLists.txt
file(GLOB_RECURSE V8_LIB # just GLOB is probably fine
"/usr/local/opt/v8/lib/*.dylib"
)
include_directories(
YOUR_INCLUDES
/usr/local/opt/v8
/usr/local/opt/v8/include
)
target_link_libraries(YOUR_PROJECT LINK_PUBLIC YOUR_LIBS ${V8_LIB})
Worked on Mojave 10.14.1
add a comment |
The usual approach is to have a step in your build system that builds the V8 library as a dependency (as well as any other dependencies you might have). For that, it should use the official V8 build instructions. If you have a split between steps to get sources/dependencies and compiling them, then getting depot_tools and calling fetch_v8
/gclient sync
belongs in there. Note that you probably want to pin a version (latest stable branch) rather than using tip-of-tree. So, in pseudocode, you'd have something like:
step get_dependencies:
download/update depot_tools
download/update V8 @ pinned_revision (using depot_tools)
step compile (depends on "get_dependencies"):
cd v8; gn args out/...; ninja -C out/...;
cd sdl; build sdl
build your own code, linking against V8/sdl/other deps.
Many build systems already have convenient ways to do these things. I don't know CMake very well though, so I can't suggest anything specific there.
I agree that using scripts to automatically modify BUILD.gn
feels wrong. It'll probably also turn out to be brittle and high-maintenance over time.
Thanks for the answer, I tried that using this stackoverflow.com/questions/44859161/… but I get missing symbols and my own method with globbingv8/out/*.o
but I get duplicate errors. I can't find documentation on what to include or even if this is supported
– c_mcg
Nov 19 '18 at 20:04
The official documentation is at v8.dev/docs/embed. Putting those command lines into your cmake files should do the trick?
– jmrk
Nov 20 '18 at 18:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379099%2fc-v8-embedding-project-structure%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I got V8 building with CMake very easily using brew:
brew install v8
then add the following lines to CMakeLists.txt
file(GLOB_RECURSE V8_LIB # just GLOB is probably fine
"/usr/local/opt/v8/lib/*.dylib"
)
include_directories(
YOUR_INCLUDES
/usr/local/opt/v8
/usr/local/opt/v8/include
)
target_link_libraries(YOUR_PROJECT LINK_PUBLIC YOUR_LIBS ${V8_LIB})
Worked on Mojave 10.14.1
add a comment |
I got V8 building with CMake very easily using brew:
brew install v8
then add the following lines to CMakeLists.txt
file(GLOB_RECURSE V8_LIB # just GLOB is probably fine
"/usr/local/opt/v8/lib/*.dylib"
)
include_directories(
YOUR_INCLUDES
/usr/local/opt/v8
/usr/local/opt/v8/include
)
target_link_libraries(YOUR_PROJECT LINK_PUBLIC YOUR_LIBS ${V8_LIB})
Worked on Mojave 10.14.1
add a comment |
I got V8 building with CMake very easily using brew:
brew install v8
then add the following lines to CMakeLists.txt
file(GLOB_RECURSE V8_LIB # just GLOB is probably fine
"/usr/local/opt/v8/lib/*.dylib"
)
include_directories(
YOUR_INCLUDES
/usr/local/opt/v8
/usr/local/opt/v8/include
)
target_link_libraries(YOUR_PROJECT LINK_PUBLIC YOUR_LIBS ${V8_LIB})
Worked on Mojave 10.14.1
I got V8 building with CMake very easily using brew:
brew install v8
then add the following lines to CMakeLists.txt
file(GLOB_RECURSE V8_LIB # just GLOB is probably fine
"/usr/local/opt/v8/lib/*.dylib"
)
include_directories(
YOUR_INCLUDES
/usr/local/opt/v8
/usr/local/opt/v8/include
)
target_link_libraries(YOUR_PROJECT LINK_PUBLIC YOUR_LIBS ${V8_LIB})
Worked on Mojave 10.14.1
answered Nov 24 '18 at 20:57
c_mcg
112
112
add a comment |
add a comment |
The usual approach is to have a step in your build system that builds the V8 library as a dependency (as well as any other dependencies you might have). For that, it should use the official V8 build instructions. If you have a split between steps to get sources/dependencies and compiling them, then getting depot_tools and calling fetch_v8
/gclient sync
belongs in there. Note that you probably want to pin a version (latest stable branch) rather than using tip-of-tree. So, in pseudocode, you'd have something like:
step get_dependencies:
download/update depot_tools
download/update V8 @ pinned_revision (using depot_tools)
step compile (depends on "get_dependencies"):
cd v8; gn args out/...; ninja -C out/...;
cd sdl; build sdl
build your own code, linking against V8/sdl/other deps.
Many build systems already have convenient ways to do these things. I don't know CMake very well though, so I can't suggest anything specific there.
I agree that using scripts to automatically modify BUILD.gn
feels wrong. It'll probably also turn out to be brittle and high-maintenance over time.
Thanks for the answer, I tried that using this stackoverflow.com/questions/44859161/… but I get missing symbols and my own method with globbingv8/out/*.o
but I get duplicate errors. I can't find documentation on what to include or even if this is supported
– c_mcg
Nov 19 '18 at 20:04
The official documentation is at v8.dev/docs/embed. Putting those command lines into your cmake files should do the trick?
– jmrk
Nov 20 '18 at 18:39
add a comment |
The usual approach is to have a step in your build system that builds the V8 library as a dependency (as well as any other dependencies you might have). For that, it should use the official V8 build instructions. If you have a split between steps to get sources/dependencies and compiling them, then getting depot_tools and calling fetch_v8
/gclient sync
belongs in there. Note that you probably want to pin a version (latest stable branch) rather than using tip-of-tree. So, in pseudocode, you'd have something like:
step get_dependencies:
download/update depot_tools
download/update V8 @ pinned_revision (using depot_tools)
step compile (depends on "get_dependencies"):
cd v8; gn args out/...; ninja -C out/...;
cd sdl; build sdl
build your own code, linking against V8/sdl/other deps.
Many build systems already have convenient ways to do these things. I don't know CMake very well though, so I can't suggest anything specific there.
I agree that using scripts to automatically modify BUILD.gn
feels wrong. It'll probably also turn out to be brittle and high-maintenance over time.
Thanks for the answer, I tried that using this stackoverflow.com/questions/44859161/… but I get missing symbols and my own method with globbingv8/out/*.o
but I get duplicate errors. I can't find documentation on what to include or even if this is supported
– c_mcg
Nov 19 '18 at 20:04
The official documentation is at v8.dev/docs/embed. Putting those command lines into your cmake files should do the trick?
– jmrk
Nov 20 '18 at 18:39
add a comment |
The usual approach is to have a step in your build system that builds the V8 library as a dependency (as well as any other dependencies you might have). For that, it should use the official V8 build instructions. If you have a split between steps to get sources/dependencies and compiling them, then getting depot_tools and calling fetch_v8
/gclient sync
belongs in there. Note that you probably want to pin a version (latest stable branch) rather than using tip-of-tree. So, in pseudocode, you'd have something like:
step get_dependencies:
download/update depot_tools
download/update V8 @ pinned_revision (using depot_tools)
step compile (depends on "get_dependencies"):
cd v8; gn args out/...; ninja -C out/...;
cd sdl; build sdl
build your own code, linking against V8/sdl/other deps.
Many build systems already have convenient ways to do these things. I don't know CMake very well though, so I can't suggest anything specific there.
I agree that using scripts to automatically modify BUILD.gn
feels wrong. It'll probably also turn out to be brittle and high-maintenance over time.
The usual approach is to have a step in your build system that builds the V8 library as a dependency (as well as any other dependencies you might have). For that, it should use the official V8 build instructions. If you have a split between steps to get sources/dependencies and compiling them, then getting depot_tools and calling fetch_v8
/gclient sync
belongs in there. Note that you probably want to pin a version (latest stable branch) rather than using tip-of-tree. So, in pseudocode, you'd have something like:
step get_dependencies:
download/update depot_tools
download/update V8 @ pinned_revision (using depot_tools)
step compile (depends on "get_dependencies"):
cd v8; gn args out/...; ninja -C out/...;
cd sdl; build sdl
build your own code, linking against V8/sdl/other deps.
Many build systems already have convenient ways to do these things. I don't know CMake very well though, so I can't suggest anything specific there.
I agree that using scripts to automatically modify BUILD.gn
feels wrong. It'll probably also turn out to be brittle and high-maintenance over time.
answered Nov 19 '18 at 19:16
jmrk
5,715727
5,715727
Thanks for the answer, I tried that using this stackoverflow.com/questions/44859161/… but I get missing symbols and my own method with globbingv8/out/*.o
but I get duplicate errors. I can't find documentation on what to include or even if this is supported
– c_mcg
Nov 19 '18 at 20:04
The official documentation is at v8.dev/docs/embed. Putting those command lines into your cmake files should do the trick?
– jmrk
Nov 20 '18 at 18:39
add a comment |
Thanks for the answer, I tried that using this stackoverflow.com/questions/44859161/… but I get missing symbols and my own method with globbingv8/out/*.o
but I get duplicate errors. I can't find documentation on what to include or even if this is supported
– c_mcg
Nov 19 '18 at 20:04
The official documentation is at v8.dev/docs/embed. Putting those command lines into your cmake files should do the trick?
– jmrk
Nov 20 '18 at 18:39
Thanks for the answer, I tried that using this stackoverflow.com/questions/44859161/… but I get missing symbols and my own method with globbing
v8/out/*.o
but I get duplicate errors. I can't find documentation on what to include or even if this is supported– c_mcg
Nov 19 '18 at 20:04
Thanks for the answer, I tried that using this stackoverflow.com/questions/44859161/… but I get missing symbols and my own method with globbing
v8/out/*.o
but I get duplicate errors. I can't find documentation on what to include or even if this is supported– c_mcg
Nov 19 '18 at 20:04
The official documentation is at v8.dev/docs/embed. Putting those command lines into your cmake files should do the trick?
– jmrk
Nov 20 '18 at 18:39
The official documentation is at v8.dev/docs/embed. Putting those command lines into your cmake files should do the trick?
– jmrk
Nov 20 '18 at 18:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379099%2fc-v8-embedding-project-structure%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It would probably be a good idea to make an adapter for v8 and sdl build systems incapsulating their build process details and exposing desired build interface.
– VTT
Nov 19 '18 at 16:51
@VTT I'm not sure exactly how the V8 build system is supposed to be used. They have a custom build scripting language (gm or gn, I'm not sure) which I don't think is required to learn (all of it) to use this project. As far as I can tell, the main way is the way I'm using it but it seems very wrong and I can't find anything telling me otherwise
– c_mcg
Nov 19 '18 at 17:05
Yeah, they have that weird GN system now, but you don't need to switch your project to use that build system. Just make an adapter so you can deal with your own and third-party projects in the uniform manner.
– VTT
Nov 19 '18 at 17:13
@VTT Okay, my project is actually split into a dynamic library (which includes SDL) and a (small) executable that includes that dynamic library. I could build the runtime as I have been and add my library as a dependency in their build system which sounds like it might work. Thanks for the help!
– c_mcg
Nov 19 '18 at 17:24