预处理程序定义是否已编译到库中? [英] Are Preprocessor Definitions compiled into a library?

查看:64
本文介绍了预处理程序定义是否已编译到库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它们(预处理程序定义)是否已编译为静态/动态库?例如, FBX SDK 需要 KFBX_DLLINFO 。使用 FBX SDK 的库必须包含该库。现在,从我的有限实验中可以看出,客户端应用程序无需再次声明该定义。

Are they (preprocessor definitions) compiled into a static/dynamic library? For example, the FBX SDK needs KFBX_DLLINFO. A library that makes use of FBX SDK must include that. Now the client application, as far as I can tell from my limited experimentation, does not need to declare the definition again.

现在我想不出更实际的情况,但是如果客户端应用程序需要排除该定义(例如 _CRT_SECURE_NO_WARNINGS),该怎么办? 使用库编译,但是如果我需要这些警告怎么办?

Now I can't think of a more practical scenario, but what if the client application 'needs' the definition to excluded (for example _CRT_SECURE_NO_WARNINGS compiled with a library, but what if I need those warnings?

推荐答案

简而言之:不。

总之:
在大多数情况下,您可以将预处理器定义视为文本替换机制。它们在编译发生之前进行处理( pre -compilation),这样它们就可以在编译器将源代码转换为机器代码,中间文件或目标文件之前转换源代码。当您拥有二进制lib / obj / dll / exe / so文件时,预处理器的定义早就消失了。

In long: For the most part, you can think of preprocessor definitions as a textual substitution mechanism. They are processed before compilation occurs (pre-compilation), so they transform the source code just before the compiler translates it to machine code, intermediate files, or whatever its target is. By the time you have a binary lib/obj/dll/exe/so file, the preprocessor definitions are long gone.

如果在代码中包含一个标头,该标头作为库的一部分打包在一起(例如,为了引用方法,类型,枚举) ,等等),那么您将包括该库定义了i的预处理器定义在该标头中。

If you include a header in your code that was packaged as part of the library (e.g. in order to reference methods, types, enums, etc. defined by the library), then you are including preprocessor definitions that the library defines in that header.

在您的情况下,如果包含FBX标头,则可能还会提取 KFBX_DLLINFO 。几乎可以肯定,您要链接的FBX二进制库是使用相同的标头构建的,因此您要根据相同的定义进行构建。这是使用C / C ++编写的库的一种常见模式:通用的共享头文件以及要构建的静态或动态库。

In your case, if you include an FBX header, you might also be pulling in the preprocessor definition of KFBX_DLLINFO. The FBX binary library you're linking against was almost certainly built with that same header, so you are building against the same definition. This is a common pattern with libraries written in C/C++: common, shared header files along with a static or dynamic lib to build against.

这篇关于预处理程序定义是否已编译到库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆