c ++ stl __declspec(noreturn)void编译错误

时间:2011-08-28 14:33:32

标签: c++ visual-studio stl

编译本机C ++ DLL时(VS2008 SP1上)出现编译错误。

错误是:

error C2062: type 'void' unexpected        c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\functional

“功能”中的行是:

 _CRTIMP2_PURE __declspec(noreturn) void __CLRCALL_PURE_OR_CDECL _Xfunc();

奇怪的是,在我为VS2008安装team explorer之前没有发生过这个错误。

我在VC ++ 2010中编译时也注意到了类似的问题:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\vector(1425): error C2062: type 'void' unexpected.

“vector”中的行是:

__declspec(noreturn) void _Xlen() const

您知道Microsoft是否更改了某些语法规则。 我使用vcproj属性玩了很多,但它根本没用。

谢谢!

我的.vcproj文件(根据要求):

<?xml version="1.0" encoding="windows-1255"?>
<VisualStudioProject
    ProjectType="Visual C++"
    Version="9.00"
    Name="ProjectNamespace"
    ProjectGUID="{C5FA75AB-0476-46A5-AAF6-1A7D03E90763}"
    RootNamespace="ProjectName"
    SccProjectName="SAK"
    SccAuxPath="SAK"
    SccLocalPath="SAK"
    SccProvider="SAK"
    Keyword="ManagedCProj"
    TargetFrameworkVersion="196613"
    >
    <Platforms>
        <Platform
            Name="Win32"
        />
    </Platforms>
    <ToolFiles>
    </ToolFiles>
    <Configurations>
        <Configuration
            Name="Debug|Win32"
            OutputDirectory=".\Debug"
            IntermediateDirectory=".\Debug"
            ConfigurationType="2"
            InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
            UseOfMFC="1"
            CharacterSet="1"
            ManagedExtensions="0"
            >
            <Tool
                Name="VCPreBuildEventTool"
            />
            <Tool
                Name="VCCustomBuildTool"
            />
            <Tool
                Name="VCXMLDataGeneratorTool"
            />
            <Tool
                Name="VCWebServiceProxyGeneratorTool"
            />
            <Tool
                Name="VCMIDLTool"
            />
            <Tool
                Name="VCCLCompilerTool"
                Optimization="0"
                AdditionalIncludeDirectories=""
                PreprocessorDefinitions="WIN32;_DEBUG;_USRDLL;ProjectName_EXPORTS;_USE_32BIT_TIME_T"
                MinimalRebuild="false"
                ExceptionHandling="1"
                BasicRuntimeChecks="3"
                RuntimeLibrary="1"
                UsePrecompiledHeader="1"
                PrecompiledHeaderFile=".\Debug/ProjectName.pch"
                AssemblerListingLocation=".\Debug/"
                ObjectFile=".\Debug/"
                ProgramDataBaseFileName=".\Debug/"
                WarningLevel="3"
                SuppressStartupBanner="true"
                DebugInformationFormat="4"
            />
            <Tool
                Name="VCManagedResourceCompilerTool"
            />
            <Tool
                Name="VCResourceCompilerTool"
            />
            <Tool
                Name="VCPreLinkEventTool"
            />
            <Tool
                Name="VCLinkerTool"
                IgnoreImportLibrary="false"
                AdditionalDependencies="ws2_32.lib Mswsock.lib Advapi32.lib"
                OutputFile="Debug\ProjectName.dll"
                LinkIncremental="2"
                SuppressStartupBanner="true"
                AdditionalLibraryDirectories=""
                ManifestFile="$(IntDir)\$(TargetFileName).intermediate.manifest"
                IgnoreAllDefaultLibraries="false"
                ModuleDefinitionFile=".\ProjectName.def"
                GenerateDebugInformation="true"
                AssemblyDebug="0"
                ProgramDatabaseFile=".\Debug/ProjectName.pdb"
                RandomizedBaseAddress="1"
                FixedBaseAddress="0"
                DataExecutionPrevention="0"
                ImportLibrary=".\Debug/ProjectName.lib"
                TargetMachine="1"
            />
            <Tool
                Name="VCALinkTool"
            />
            <Tool
                Name="VCManifestTool"
            />
            <Tool
                Name="VCXDCMakeTool"
            />
            <Tool
                Name="VCBscMakeTool"
            />
            <Tool
                Name="VCFxCopTool"
            />
            <Tool
                Name="VCAppVerifierTool"
            />
            <Tool
                Name="VCPostBuildEventTool"
            />
        </Configuration>
        <Configuration
            Name="Release|Win32"
            OutputDirectory="$(ConfigurationName)"
            IntermediateDirectory="$(ConfigurationName)"
            ConfigurationType="2"
            CharacterSet="0"
            ManagedExtensions="0"
            WholeProgramOptimization="1"
            >
            <Tool
                Name="VCPreBuildEventTool"
            />
            <Tool
                Name="VCCustomBuildTool"
            />
            <Tool
                Name="VCXMLDataGeneratorTool"
            />
            <Tool
                Name="VCWebServiceProxyGeneratorTool"
            />
            <Tool
                Name="VCMIDLTool"
            />
            <Tool
                Name="VCCLCompilerTool"
                PreprocessorDefinitions="WIN32;NDEBUG;_USE_32BIT_TIME_T"
                ExceptionHandling="0"
                RuntimeLibrary="2"
                UsePrecompiledHeader="2"
                WarningLevel="3"
                DebugInformationFormat="3"
            />
            <Tool
                Name="VCManagedResourceCompilerTool"
            />
            <Tool
                Name="VCResourceCompilerTool"
            />
            <Tool
                Name="VCPreLinkEventTool"
            />
            <Tool
                Name="VCLinkerTool"
                AdditionalDependencies="ws2_32.lib Mswsock.lib Advapi32.lib"
                LinkIncremental="1"
                ModuleDefinitionFile=".\ProjectName.def"
                GenerateDebugInformation="true"
                TargetMachine="1"
            />
            <Tool
                Name="VCALinkTool"
            />
            <Tool
                Name="VCManifestTool"
            />
            <Tool
                Name="VCXDCMakeTool"
            />
            <Tool
                Name="VCBscMakeTool"
            />
            <Tool
                Name="VCFxCopTool"
            />
            <Tool
                Name="VCAppVerifierTool"
            />
            <Tool
                Name="VCPostBuildEventTool"
            />
        </Configuration>
    </Configurations>
    <References>
        <AssemblyReference
            RelativePath="System.dll"
            AssemblyName="System, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
            MinFrameworkVersion="131072"
        />
        <AssemblyReference
            RelativePath="System.Data.dll"
            AssemblyName="System.Data, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86"
            MinFrameworkVersion="131072"
        />
        <AssemblyReference
            RelativePath="System.XML.dll"
            AssemblyName="System.Xml, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
            MinFrameworkVersion="131072"
        />
    </References>
    <Files>
        <Filter
            Name="Source Files"
            Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
            UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
            >
            <File
                RelativePath=".\common.cpp"
                >
            </File>
            <File
                RelativePath=".\ProjectName.cpp"
                >
            </File>
            <File
                RelativePath=".\ProjectName.def"
                >
            </File>
            <File
                RelativePath=".\MessageCracker.cpp"
                >
            </File>
            <File
                RelativePath=".\PlaceTradeManager.cpp"
                >
            </File>
            <File
                RelativePath=".\RequestsManager.cpp"
                >
            </File>
            <File
                RelativePath=".\Stdafx.cpp"
                >
                <FileConfiguration
                    Name="Debug|Win32"
                    >
                    <Tool
                        Name="VCCLCompilerTool"
                        UsePrecompiledHeader="1"
                    />
                </FileConfiguration>
                <FileConfiguration
                    Name="Release|Win32"
                    >
                    <Tool
                        Name="VCCLCompilerTool"
                        UsePrecompiledHeader="1"
                    />
                </FileConfiguration>
            </File>
            <File
                RelativePath=".\TCPClient.cpp"
                >
            </File>
            <Filter
                Name="config"
                >
                <File
                    RelativePath=".\config\Configuration.cpp"
                    >
                </File>
                <File
                    RelativePath=".\config\stringfile.cpp"
                    >
                </File>
            </Filter>
        </Filter>
        <Filter
            Name="Header Files"
            Filter="h;hpp;hxx;hm;inl;inc;xsd"
            UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
            >
            <File
                RelativePath=".\common.h"
                >
            </File>
            <File
                RelativePath=".\ProjectName.h"
                >
            </File>
            <File
                RelativePath=".\MessageCracker.h"
                >
            </File>
            <File
                RelativePath=".\Messages.h"
                >
            </File>
            <File
                RelativePath=".\Include1.h"
                >
            </File>
            <File
                RelativePath=".\Include2.h"
                >
            </File>
            <File
                RelativePath=".\resource.h"
                >
            </File>
            <File
                RelativePath=".\Stdafx.h"
                >
            </File>
            <File
                RelativePath=".\Sync.h"
                >
            </File>
            <File
                RelativePath=".\TCPClient.h"
                >
            </File>
            <Filter
                Name="config"
                >
                <File
                    RelativePath=".\config\Configuration.h"
                    >
                </File>
                <File
                    RelativePath=".\config\stringfile.h"
                    >
                </File>
            </Filter>
        </Filter>
        <Filter
            Name="Resource Files"
            Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
            UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
            >
            <File
                RelativePath=".\app.ico"
                >
            </File>
        </Filter>
    </Files>
    <Globals>
    </Globals>
</VisualStudioProject>

1 个答案:

答案 0 :(得分:1)

尝试将__declspec 放在 _CRTIMP2_PURE之前而不是之后。这就是the documentation for __declspec(noreturn)的作用。