我一直在尝试构建V8并使用c ++将最简单的项目链接到它,但是有关libc ++的错误却不断出现,但我不确定如何解决。 (我的大多数c ++经验都在Windows上,但是我正在ubuntu上构建它,我已经尝试了16.04和18.04)
存在太多错误,无法将所有错误都发布到此处,但似乎它们都与std :: __ 1 :: {something}有关。这是一个示例:
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = null;
try {
sc = new Scanner(new File("input.txt"), "UTF-8");
while(sc.hasNext())
System.out.println(sc.nextLine());
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if(sc!=null) sc.close();
}
}
}
main.cpp的内容:
নমঃ নমঃ নামো বাঙালাদেশ মম
চির মনোরম চির মধুর
বৃকে নিরবধি বহে শত নদী
চরণে জলধির বাজে নূপুর।।
গ্রীষ্মে নাচে বামা কালবোশেখি ঝড়ে
সহসা বরষাতে কাঁদিয়া ভেঙ্গে পড়ে
শরতে হেসে চলে শেফালিকা-তলে
我用来构建它的命令:
main.cpp:(.text+0x53): undefined reference to v8::platform::NewDefaultPlatform(int, v8::platform::IdleTaskSupport, v8::platform::InProcessStackDumping, std::unique_ptr<v8::TracingController, std::default_delete<v8::TracingController> >)'
./v8/out.gn/x64.release/obj//libv8_monolith.a(api.o): In function `v8::SnapshotCreator::CreateBlob(v8::SnapshotCreator::FunctionCodeHandling)':
api.cc:(.text._ZN2v815SnapshotCreator10CreateBlobENS0_20FunctionCodeHandlingE+0x10e7): undefined reference to `std::__1::__vector_base_common<true>::__throw_length_error() const'
api.cc:(.text._ZN2v815SnapshotCreator10CreateBlobENS0_20FunctionCodeHandlingE+0x10f3): undefined reference to `std::__1::__vector_base_common<true>::__throw_length_error() const'
这是我用来构建V8并用作该命令参考的文档: https://v8.dev/docs/embed
请让我知道是否需要更多信息!
编辑:
所有的教程和示例代码都包含“ #include
#include <v8.h>
#include <libplatform/libplatform.h>
int main(int argc, char** argv) {
v8::V8::InitializeICU();
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
return 0;
}
解决方案: 安装libc ++-dev和clang ubuntu软件包并使用此行进行编译使所有工作正常:
g++ -I. -I./v8/include main.cpp -o testv8 -lv8_monolith -L./v8/out.gn/x64.release/obj/ -pthread -std=c++0x