编译检查是否编译为静态库 [英] Compile check if compiling as static library

查看:104
本文介绍了编译检查是否编译为静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检查项目是否以lib的形式进行编译? (静态库)

How can i check at compilation if the project is being compiles as a lib ? (static library)

我可以检查某种静态断言或其他标志吗?

Is there some kind of static assert or some other flag i can check?

I我自己不能添加预处理器变量,因为它是一个实用程序,将在公司的其他项目中使用。因此,我想知道默认情况下是否发送了一些预处理器标记。

I can't add a preprocessor variable myself, because it's a utility that will be used in other projects across the company. So I'm wondering if there's some preprocessor flag that is is being sent by default or something.

我正在使用Visual Studio 2010

I'm using Visual Studio 2010

推荐答案

预定义的宏列表中没有这样的东西- http://msdn.microsoft.com/zh-CN/library/b0084kay%28v=vs.100%29.aspx

There is no such thing in predefined macro list - http://msdn.microsoft.com/en-us/library/b0084kay%28v=vs.100%29.aspx .

但是,默认情况下,如果是静态库项目,MSVC会将 _LIB 添加到预处理器定义列表中。 >
(还会为DLL添加 _USRDLL

But by default MSVC adds _LIB to preprocessor definition list, if it's a "static library" project.
(also it adds _USRDLL for DLLs)

编辑:在Visual Studio 2017中,DLL的定义为 _WINDLL (来自IDE应用的 Windows动态链接库属性表)。 _LIB 定义不再可用。

In Visual Studio 2017 the definition for DLLs is _WINDLL (from the "Windows Dynamic Link Library" property sheet applied by the IDE). The _LIB definition is no longer available.

另一种解决方案是使用以下预处理器定义向项目添加属性表(签入版本控制存储库): _ $( OutputType);%(PreprocessorDefinitions)

An alternative solution is to add a property sheet to the project (checked into your version control repository) with the following preprocessor definition: _$(OutputType);%(PreprocessorDefinitions).

$(OutputType)将解析为DLL的 library和静态库的 staticlibrary,分别导致 _library _staticlibrary 定义(或 _exe (对于应用程序)。

$(OutputType) will resolve as "library" for DLLs and "staticlibrary" for static libraries, resulting in _library and _staticlibrary definitions respectively (or _exe for applications).

%(PreprocessorDefinitions)将堆叠先前属性表中的定义。

%(PreprocessorDefinitions) will stack definitions from previous property sheets. Make sure it is included in the project properties as well!

要添加属性表,请导航至视图|。其他Windows | Visual Studio中的媒体资源管理器

To add a property sheet, navigate to View | Other Windows | Property Manager in Visual Studio.

这篇关于编译检查是否编译为静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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