dll 导出/初始化问题(静态变量初始化?)Visual Studio C++

发布于 2024-11-15 19:41:27 字数 900 浏览 4 评论 0原文

我想运行 CLANG/LLVM 的示例插件。具体来说是llvm\tools\clang\examples\PrintFunctionNames。我设法构建它,并且看到一个 PrintFunctionNames.exports 但我不认为 Visual Studios 支持它。该文件只是_ZN4llvm8Registry*。我不知道那是什么,但我怀疑它的命名空间 llvm,类注册表的定义是因为

template <typename T, typename U = RegistryTraits<T> >
class Registry {

我怀疑关键行位于示例文件的末尾

static FrontendPluginRegistry::Add<PrintFunctionNamesAction> X("print-fns", "print function names");

print-fns 是名称,而第二个参数是 desc。当我尝试通过加载/运行 dll 时

clang -cc1 -load printFunctionNames.dll -plugin print-fns a.c

,出现找不到 print-fns 的错误。我怀疑它是因为静态变量永远不会被初始化,因此它永远不会注册插件。错误的 dll 名称会导致加载模块消息出错。

我创建了一个 def 文件并将其添加到我的项目中。它编译了但仍然没有运气。这是我的 def 文件

LIBRARY printFunctionNames
EXPORTS
X DATA

我如何注册插件或让这个示例正常工作?

I want to run an example plugin for CLANG/LLVM. Specifically llvm\tools\clang\examples\PrintFunctionNames. I managed to build it and i see an PrintFunctionNames.exports but i dont think visual studios supports it. The file is simply _ZN4llvm8Registry*. I have no idea what that is but i suspect its namespace llvm, class Registry which is defined as

template <typename T, typename U = RegistryTraits<T> >
class Registry {

I suspect the key line is at the end of the example file

static FrontendPluginRegistry::Add<PrintFunctionNamesAction> X("print-fns", "print function names");

print-fns is the name while the 2nd param is the desc. When i try loading/running the dll via

clang -cc1 -load printFunctionNames.dll -plugin print-fns a.c

I get an error about not finding print-fns. I suspect its because the static variable is never being initialize thus it never registers the plugin. A wrong dll name would get an error loading module msg.

I created a def file and added it to my project. It compiled but still no luck. Here is my def file

LIBRARY printFunctionNames
EXPORTS
X DATA

How do i register the plugin or get this example working?

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

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

发布评论

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

评论(2

葮薆情 2024-11-22 19:41:27

好的,变得稍微清楚一些。总结一下:Visual Studio 确实与此无关。这是 clang 可执行文件的插件。因此,它们之间必须有一种通信的方法(插件接口)。这似乎是一个未记录的接口,因此可以减少一些猜测。

DLL 问题的故障排除是通过“Dependency Walker”(又名“Depends”)完成的。它提供了一种分析模式,可以分析所有符号查找。也就是说,如果您分析clang -cc1 -load printFunctionNames.dll -plugin print-fns ac,您将看到clang期望从您的DLL中获得什么符号,以及按什么顺序。

Ok, becoming slightly more clear. To summarize: Visual Studio has nothing to do with it, really. This is a plugin for the clang executable. Therefore, there must be a method to communicate between them (the plugin interface). This appears to be an undocumented interface, so it's taking a bit off guesswork.

Troubleshooting DLL issues is done with "Dependency Walker" aka "Depends". It offers a profiling mode, in which all symbol lookups can be profiled. I.e. if you profile clang -cc1 -load printFunctionNames.dll -plugin print-fns a.c, you will see what symbols clang expects from your DLL, and in what order.

对你再特殊 2024-11-22 19:41:27

看起来您正在尝试混合使用两个不同的、不兼容的编译器构建的 C++ 代码。这是不支持的,您看到的错误是一个典型的迹象:C++ 编译器通常使用“名称修改方案”,如果两个编译器不兼容,那么它们的名称修改方案不会对齐。一个编译器可能会将 llvm::Registry 损坏为 _ZN4llvm8Registry*,而另一个编译器则将其引用为 llvm__Registry

It looks like you're trying to mix C++ code built with two different, incompatible compilers. That's not supported, and the error you're seeing is a typical sign of that: C++ compilers usually use a "name mangling scheme", and if two compilers are incompatible then their name mangling schemes don't line up. One compiler may mangle llvm::Registry as _ZN4llvm8Registry* while another refers to it as llvm__Registry.

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