Compile check if compiling as a static library

How can I check at compilation if the project compiles as lib? (static library)

Is there any static assert or any other flag that I can check?

I cannot add a preprocessor variable myself, because it is a utility that will be used in other projects in the company. So I am wondering if there is some kind of preprocessor flag that is sent by default or something like that.

I am using Visual Studio 2010

+6
source share
3 answers

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

But by default, MSVC adds _LIB to the preprocessor definition list if it is a "static library" project.
(he also adds _USRDLL for the DLL)

+5
source

If you are using Visual Studio, I do not quite understand what is wrong with adding your own preprocessor. The reason is that you still have to supply project files, so the option will be correctly distributed with the project file.

Or you could mean "how to check if a file compiles as a library" - there is no way (other than defining a compiler).

+1
source

What creates a specific assembly, which is explicitly specified in the vcxproj file, it is known and set before compilation. What can be difficult is that in the settings of your solution file displayed in the configuration manager, your solution configuration and platform may have been resolved using some kind of uncertain configuration of the project and platform that diverge in your solution assembly.

In the vcxproj xml file, the assembly output type will be displayed as the value for the <ConfigurationType> element.

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <ConfigurationType>StaticLibrary</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> <WholeProgramOptimization>true</WholeProgramOptimization> <CharacterSet>MultiByte</CharacterSet> </PropertyGroup> 

Similarly, on the project properties page in Configuration Properties -> General -> Configuration Type you specify how assemblies are built. You can even deviate from the target extension if it makes sense, for example, when I create some BoostPython stuff, I change the dll to pyd.

Project property highlighting configuration type setting

To emphasize the kind of funny mix that I’m talking about that might have happened by mistake or erroneous merging or something else, you can check what your detailed build options for each project are in the solution configuration. Below is an example where the solution platform is ReleaseOffline, but the various projects in the solution are typed in Release, DebugStatic, etc. Many of the projects are disabled in the screenshot, but you can imagine that mixing dependencies leads to bad types of mixing states. Some mixes may be intentional, so make sure you know what you are doing / looking for, as Visual Studio provides such flexibility in these configurations. Remember also that the settings you see are specific to the configuration / platform pair that is selected. Change any of them, and you are likely to see changes in the values ​​for all of which were mentioned above.

Example configuration configuration configuration configuration in the configuration manager

0
source

All Articles