MSVC - boost::python 静态链接到 .dll (.pyd)

发布于 2024-10-01 05:38:51 字数 413 浏览 6 评论 0原文

我有一个 VS10 项目。我想构建一些 C++ 代码,以便可以在 python 中使用它。我按照 boost 教程进行操作并使其正常工作。然而,VS 保持链接 boost-python-vc100-mt-gd-1_44.lib 但它只是一个调用 boost-python-vc100-mt-gd-1_44.dll 的包装器。这就是为什么我需要将 .dll 与我的 .dll(.pyd) 文件一起复制。所以我想将 boost:python 静态链接到该 .dll(.pyd) 文件。但我在 VS 或编译器和链接器手册中找不到任何配置选项。最奇怪的事情是我有一个使用 boost::filesystem 的旧项目,其配置完全相同,但该项目链接到 libboost-filesystem-*.lib 这是静态库,所以没关系。我已经用谷歌搜索了几个小时,但没有成功,这让我发疯。

感谢您的任何帮助或建议。

I got a VS10 project. I want to build some C++ code so I can use it in python. I followed the boost tutorial and got it working. However VS keeps to link boost-python-vc100-mt-gd-1_44.lib but it's just a wrapper which calls boost-python-vc100-mt-gd-1_44.dll. That's why I need to copy the .dll with my .dll(.pyd) file. So I want to link boost:python statically to that .dll(.pyd) file. But I just can't find any configuration option in VS or in the compiler and linker manual. The weirdest thing is I've got one older project using boost::filesystem with the very same config but that project links against libboost-filesystem-*.lib which is static lib so it's ok. I've been googling for couple of hours without any success and it drivers me crazy.

Thanks for any help or suggestion.

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

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

发布评论

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

评论(2

橘香 2024-10-08 05:38:51

你可能不想这样做。当导入多个基于 boost python 的库时,静态链接的 Boost python 会出现许多问题和怪癖。 “但我只有一个”你说。您能保证您的用户不会再有其他人吗?您将来可能想使用另一个?坚持使用 DLL。分发另一个 DLL 确实没什么大不了的。只需将其并排放在同一目录中即可。

You probably don't want to do that. Statically linked Boost python has a number of problems and quirks when there are more then one boost python based library imported. "But I only have one" you say. Can you guarantee that your users won't have another? That you might want to use another in the future? Stick with the DLL. Distributing another DLL is really not that big a deal. Just put it side-by-side in the same directory.

轻许诺言 2024-10-08 05:38:51

链接哪些库取决于您的项目的设置。有两种可能性: 您可以针对

  1. 静态
  2. 动态

C 运行时库的 链接版本进行构建。根据选择的选项,boost 会向链接器发送正确的#pragma。这些选项需要在构成您的程序的所有项目中保持一致。因此,转到“属性 -> c++ -> 代码生成”(或类似的,我只是猜测,现在没有启动并运行 VS)并确保设置了正确的选项(一致)。当然,你必须先编译好所需格式的boost库...

What libraries are linked depends on the settings of your project. There are two possibilities: You can build against

  1. statically
  2. dynamically

linked versions of the c-runtime libs. Depending on which option is selected, the boost sends a proper #pragma to the linker. These options need to be set consistently in all projects which constitute your program. So go to "properties -> c++ -> code generation" (or similar, I am just guessing, don't have VS up and running right now) and be sure that the right option is set (consistently). Of course, you must have compiled boost libraries in required format before...

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