在我的项目中使用v8.dll时解析外部符号

发布于 2025-01-24 10:47:20 字数 2304 浏览 0 评论 0原文

我是新的C ++项目。我可能不确定C ++项目的先决条件知识。

[我的环境]

  • Windows 10
  • Python 2.7.18
  • 开发人员命令提示vs 2022
  • Visual Studio 2022 Community

我目前正在散布将V8 Engine作为DLL并使用它。

我已将V8引擎构建为DLL Successfly,但使用它,我将面临“解析外部符号”错误。

详细信息:

error LNK2019: unresolved external symbol "class std::unique_ptr<class v8::Platform,struct std::default_delete<class v8::Platform> > __cdecl v8::platform::NewDefaultPlatform(int,enum v8::platform::IdleTaskSupport,enum v8::platform::InProcessStackDumping,class std::unique_ptr<class v8::TracingController,struct std::default_delete<class v8::TracingController> >)" (?NewDefaultPlatform@platform@v8@@YA?AV?$unique_ptr@VPlatform@v8@@U?$default_delete@VPlatform@v8@@@std@@@std@@HW4IdleTaskSupport@12@W4InProcessStackDumping@12@V?$unique_ptr@VTracingController@v8@@U?$default_delete@VTracingController@v8@@@std@@@4@@Z) referenced in function "public: __cdecl ezv8::Platform::Impl::Impl(void)" (??0Impl@Platform@ezv8@@QEAA@XZ)

我已经研究了C ++杂交和曲折行为的一些事情。

我注意到v8_libplatform.dll.lib文件包含以下其他类型的操纵符号。

?NewDefaultPlatform@platform@v8@@YA?AV?$unique_ptr@VPlatform@v8@@U?$default_delete@VPlatform@v8@@@__1@std@@@__1@std@@HW4IdleTaskSupport@12@W4InProcessStackDumping@12@V?$unique_ptr@VTracingController@v8@@U?$default_delete@VTracingController@v8@@@__1@std@@@45@@Z = ?NewDefaultPlatform@platform@v8@@YA?AV?$unique_ptr@VPlatform@v8@@U?$default_delete@VPlatform@v8@@@__1@std@@@__1@std@@HW4IdleTaskSupport@12@W4InProcessStackDumping@12@V?$unique_ptr@VTracingController@v8@@U?$default_delete@VTracingController@v8@@@__1@std@@@45@@Z (class std::__1::unique_ptr<class v8::Platform,struct std::__1::default_delete<class v8::Platform> > __cdecl v8::platform::NewDefaultPlatform(int,enum v8::platform::IdleTaskSupport,enum v8::platform::InProcessStackDumping,class std::__1::unique_ptr<class v8::TracingController,struct std::__1::default_delete<class v8::TracingController> >))

如您所见,.lib文件包含__ 1名称空间的符号。

我发现了为什么文件包含的原因。捆绑的clang编译器编译std带有内联命名空间__ 1的名称空间,但是我不确定我如何在没有__ 1内联命名空间的情况下更改编译。

有人知道如何改变编译器的行为吗?

I'm new to making C++ project. I may be not sure prerequisite knowledge of C++ project.

[My environment]

  • Windows 10
  • Python 2.7.18
  • Developer Command Prompt for VS 2022
  • Visual Studio 2022 Community

I'm currently straggling with making V8 engine as a DLL and using it.

I've built V8 engine as a DLL successfly but using it I'm facing "Unresolve exteranl symbols" error.

Details:

error LNK2019: unresolved external symbol "class std::unique_ptr<class v8::Platform,struct std::default_delete<class v8::Platform> > __cdecl v8::platform::NewDefaultPlatform(int,enum v8::platform::IdleTaskSupport,enum v8::platform::InProcessStackDumping,class std::unique_ptr<class v8::TracingController,struct std::default_delete<class v8::TracingController> >)" (?NewDefaultPlatform@platform@v8@@YA?AV?$unique_ptr@VPlatform@v8@@U?$default_delete@VPlatform@v8@@@std@@@std@@HW4IdleTaskSupport@12@W4InProcessStackDumping@12@V?$unique_ptr@VTracingController@v8@@U?$default_delete@VTracingController@v8@@@std@@@4@@Z) referenced in function "public: __cdecl ezv8::Platform::Impl::Impl(void)" (??0Impl@Platform@ezv8@@QEAA@XZ)

I've researched some thing that C++ mangling and compailer behaviours are.

I've noticed that the v8_libplatform.dll.lib file contains other type of mangled symbols like below.

?NewDefaultPlatform@platform@v8@@YA?AV?$unique_ptr@VPlatform@v8@@U?$default_delete@VPlatform@v8@@@__1@std@@@__1@std@@HW4IdleTaskSupport@12@W4InProcessStackDumping@12@V?$unique_ptr@VTracingController@v8@@U?$default_delete@VTracingController@v8@@@__1@std@@@45@@Z = ?NewDefaultPlatform@platform@v8@@YA?AV?$unique_ptr@VPlatform@v8@@U?$default_delete@VPlatform@v8@@@__1@std@@@__1@std@@HW4IdleTaskSupport@12@W4InProcessStackDumping@12@V?$unique_ptr@VTracingController@v8@@U?$default_delete@VTracingController@v8@@@__1@std@@@45@@Z (class std::__1::unique_ptr<class v8::Platform,struct std::__1::default_delete<class v8::Platform> > __cdecl v8::platform::NewDefaultPlatform(int,enum v8::platform::IdleTaskSupport,enum v8::platform::InProcessStackDumping,class std::__1::unique_ptr<class v8::TracingController,struct std::__1::default_delete<class v8::TracingController> >))

As you can see, the .lib file contains the symbol with __1 namespace.

I found out why the file contains that. A bundled clang compiler compiles std namespace with inline namespace __1 but I'm not sure that how I can change compililng without __1 inline namespace.

Does anyone know how to change the compiler behaviour?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

开始看清了 2025-01-31 10:47:20

我自己解决了这个问题。 (但是我还有其他构建中的其他错误。)

问题是我必须在gn args 中添加一个标志“ is_clang = false”到MSV。

如果添加了标志,则V8工具将使用安装的CL.EXE编译这些代码。

I resolved this problem myself. (But I get still other erros in building.)

What the problem is that I have to add a flag "is_clang = false" to gn args because the clang that is bound v8 will compile other type of manglings to MSVS.

If I added the flag then v8 tools will compile these code with cl.exe you installed.

树深时见影 2025-01-31 10:47:20

我的链接问题与v8 :: Platform :: NewDefaultPlatform()函数以及其他一些其他方法(例如v8 :: context :: scope :: scope :: scope(),v8 :: context :: scope ::〜scope()等。原因与名称杂交无关,它看起来像clang-cl(默认情况下在Windows Platform在V8/Chromium中使用)使用与CL相同的名称。所有这些方法均在标题文件中定义,因此它们实际上是嵌入式的,并且Clang-Cl使用/ZC:dllexportinlines-编译器选项,该选项不会从DLL中导出inlines(请参阅 https://reviews.llvm.org/d51340?id=172304?id = 172304

很久以前提出了添加/zc的请求:dllextortinlines选项已很久以前提出: https://develovelercommunity.visualstudio.com/t/implement-zcdllexportinlines-aka-fvisibility-inlin/374754 仍然不支持它。

因此,我看不到在没有修改V8/Chromium标头文件的情况下使用Microsoft CL编译器的V8 DLL(这永远不好)。可以将V8构建为静态库,也可以将Clang-Cl用作自定义构建工具。

至于使用is_clang = false gn参数的构建v8,我想知道这是否可能是可能的。有许多编译器选项,例如-wno-unused-const-variable-wno-unused功能,这些 不受cl的支持,但在GN构建文件中无条件添加。我记得几年前,可以使用CL建造铬,但这是吗?

I had exactly the same linking issue with v8::platform::NewDefaultPlatform() function, as well as some other methods like v8::Context::Scope::Scope(), v8::Context::Scope::~Scope() and so on. And the cause wasn't related with name mangling, it looks like clang-cl (used in v8/chromium by default on Windows platforms) uses the same name mangling as cl does. All these methods are defined in header files so they're effectively inlines, and clang-cl uses /Zc:DllexportInlines- compiler option which doesn't export inlines from DLLs (see https://reviews.llvm.org/D51340?id=172304 for details).

A request for adding /Zc:DllexportInlines option to cl compiler was raised a long time ago: https://developercommunity.visualstudio.com/t/implement-zcdllexportinlines-aka-fvisibility-inlin/374754 , but as of now, cl version 19.34.31937 still doesn't support it.

So I can see no way using v8 DLLs with Microsoft's cl compiler without modifying v8/chromium header files (which is never good). One can build v8 as static libraries, or use clang-cl as a custom build tool.

As for building v8 without clang using is_clang=false gn argument, I wonder if it's actually possible. There are many compiler options like -Wno-unused-const-variable or -Wno-unused-function which aren't supported by cl but added unconditionally in gn build files. I remember years ago it was possible to build chromium using cl, but is it now?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文