C++ V8在Ubuntu上编译示例/hello-world.cc
试图在ubuntu上编译V8示例/hello-world.ccC++ V8在Ubuntu上编译示例/hello-world.cc,c++,g++,v8,embedded-v8,C++,G++,V8,Embedded V8,试图在ubuntu上编译V8示例/hello-world.cc #include <stdio.h> #include <stdlib.h> #include <string.h> #include "include/libplatform/libplatform.h" #include "include/v8.h" int main(int argc, char* argv[]) { // Initialize V8. v8::V8::Initi
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "include/libplatform/libplatform.h"
#include "include/v8.h"
int main(int argc, char* argv[]) {
// Initialize V8.
v8::V8::InitializeICUDefaultLocation(argv[0]);
v8::V8::InitializeExternalStartupData(argv[0]);
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(platform.get());
v8::V8::Initialize();
// Create a new Isolate and make it the current one.
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator =
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
{
v8::Isolate::Scope isolate_scope(isolate);
// Create a stack-allocated handle scope.
v8::HandleScope handle_scope(isolate);
// Create a new context.
v8::Local<v8::Context> context = v8::Context::New(isolate);
// Enter the context for compiling and running the hello world script.
v8::Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
v8::Local<v8::String> source =
v8::String::NewFromUtf8(isolate, "'Hello' + ', World!'",
v8::NewStringType::kNormal)
.ToLocalChecked();
// Compile the source code.
v8::Local<v8::Script> script =
v8::Script::Compile(context, source).ToLocalChecked();
// Run the script to get the result.
v8::Local<v8::Value> result = script->Run(context).ToLocalChecked();
// Convert the result to an UTF8 string and print it.
v8::String::Utf8Value utf8(isolate, result);
printf("%s\n", *utf8);
}
// Dispose the isolate and tear down V8.
isolate->Dispose();
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete create_params.array_buffer_allocator;
return 0;
}
并得到一个错误:
hello-world.cc:(.text+0x75): undefined reference to
v8::platform::NewDefaultPlatform(int, v8::platform::IdleTaskSupport,
v8::platform::InProcessStackDumping,
std::unique_ptr<v8::TracingController,
std::default_delete<v8::TracingController> >)
hello world.cc:(.text+0x75):未定义对的引用
v8::platform::NewDefaultPlatform(int,v8::platform::IdleTaskSupport,
v8::平台::InProcessStackDumping,
标准::唯一性(ptr)
请注意,我使用GN args构建了V8:
“is_debug=false,is_official\u build=true,is_component\u build=true,is_cfi=false,is_clangg=false,v8_use\u external\u startup\u data=false,视警告为_errors=false,use_custom\u libcxx=false,use_sysroot=false,use_gold=false”
在编译器命令行中,尝试删除
\
out.gn/x64.release/libv8\u libplatform.so之后的\
,我对V8构建或编译示例/hello world.cc是否有问题\
是一个“转义”字符,因此它改变了以下空格的解释方式——具体来说,它使其成为文件名的一部分,而不是文件名分隔符,从而导致文件名不存在
这有帮助吗?如果您收到错误消息,您必须这样做。请单击“编辑”并将代码粘贴到问题中,然后格式化。添加了代码。非常好。看起来好多了。
hello-world.cc:(.text+0x75): undefined reference to
v8::platform::NewDefaultPlatform(int, v8::platform::IdleTaskSupport,
v8::platform::InProcessStackDumping,
std::unique_ptr<v8::TracingController,
std::default_delete<v8::TracingController> >)