C++ - 建设图书馆

发布于 2024-09-14 22:33:35 字数 543 浏览 9 评论 0原文

我正在 Microsoft Visual Studio 2008 SP1 中构建静态库(现在是 libpng)。

假设我的库中只有 C 代码,我是否有可能为 DebugRelease 模式构建单个库(一个文件) ?

据我记得,例如,gtkmm 有它的预构建包,其中基于 C++ 的库在 DebugRelease 中提供版本,但其他 - 仅作为单个文件。

例如,他们有用于基于 C++ 的库的 gtkmm-vc90-d-2_4.libgtkmm-vc90-2_4.lib 文件,并且他们有单个库,例如 gtk -win32-2.0.lib 用于调试发布 配置。

如何才能达到同样的效果?我应该怎么做才能使构建的库(纯C)配置独立?

I'm building static libraries (right now libpng) in Microsoft Visual Studio 2008 SP1.

Do I have any possibility to build single library (one file) for both Debug and Release modes assuming that my library has only C code in it?

As far as I remember, gtkmm, for instance, has it's pre-built package, where C++ based libraries are shipped in both Debug and Release versions, but other - as a single file only.

E.g. they have gtkmm-vc90-d-2_4.lib and gtkmm-vc90-2_4.lib files for C++ based libraries and they have single libraries such as gtk-win32-2.0.lib for both Debug and Release configurations.

How can I achieve the same effect? What should I do to make the built library (pure C) configuration-independent?

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

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

发布评论

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

评论(2

仅此而已 2024-09-21 22:33:35

理论上,如果库的所有外部标头(即由客户端拉入的标头)不使用#ifdef _DEBUG(或可能在 考虑这样的

情况:

// file: mylib.h
struct A {
   int member1;
   int member2;
   #ifdef _DEBUG
     int extraDebugOption;
   #endif
};

在这种情况下,如果您要将库链接到您自己产品的调试版本中,那么 A 将具有与发布版本不同的大小,这意味着您'将有一些非常可怕的内存损坏错误需要追踪(曾经在那里......)


忘了提及,您应该将您的一个配置设为发布配置,这样您就不会最终引用调试 CRT,并且库也会得到优化。正如 lsalamon 指出的那样,创建一个 pdb 文件并将其与 .lib 文件一起保存将有助于将来的调试。

In theory you could build just one library if all the external headers for the library (ie the ones pulled in by the client) don't use #ifdef _DEBUG (or any other macro that may be defined in a debug build but not a release build.

Consider a case like this:

// file: mylib.h
struct A {
   int member1;
   int member2;
   #ifdef _DEBUG
     int extraDebugOption;
   #endif
};

In this case, if you were to link the library into a debug build of your own product then A will have a different size to the release build, which means you're going to have some pretty horrendous memory corruption bugs to track down (been there...).

EDIT:
Forgot to mention, you should make your one configuration a Release configuration so that you don't end up with any references to the debug CRT, and also so the library is optimised. As lsalamon points out, creating a pdb file and saving this along with your .lib file will be useful in the future for debugging.

π浅易 2024-09-21 22:33:35

要在发布版本中包含调试信息,请使用此配置:
C/C++->常规->调试信息格式:程序数据库(/Zi)

链接器 -> 调试 -> 生成调试信息:是 (/DEBUG)

To include debug info at release version use this configuration :
C/C++->General->Debug Information Format: Program Database (/Zi)
and
Linker->Debugging->Generate Debug Info : Yes (/DEBUG)

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