0

我有一个包含 17 个子项目的 MFC 解决方案。我最近刚刚添加了另一个 dll 项目,无法让可执行文件链接到库的重命名版本。在解决方案中 dll 项目的设置中,调试版本都在输出名称后附加了一个“D”以表示它是调试版本。在某些情况下,我们通过将 TargetName 更改为 $(ProjectName)D 来做到这一点,而在其他情况下,构建后事件会将其从构建目录复制到 lib 目录,并将其重命名为“D”。对于这个项目,当我编译 dll 时,我得到了预期的两个文件:MultiLangD.lib 和 MultiLangD.dll。这是 dll 项目的链接器命令行:

/OUT:".\Debug\MultiLangD.dll" /NOLOGO /DLL /MANIFEST 
/ManifestFile:".\Debug\MultiLangD.dll.intermediate.manifest" /ALLOWISOLATION 
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG 
/PDB:"C:\WorkSpaces\WorkSpace_CFFT_II_i18n\CFFT_i18n_MBCS\CFFT\MultiLang\Debug\MultiLangD.pdb" 
/PGD:"C:\WorkSpaces\WorkSpace_CFFT_II_i18n\CFFT_i18n_MBCS\CFFT\MultiLang\Debug\MultiLangD.pgd" 
/TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:".\Debug\MultiLangD.lib" /MACHINE:X86 
/ERRORREPORT:QUEUE 

这是 dll 项目的编译器命令行:

/ZI /nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_WINDOWS" /D "_DEBUG" /D "_AFXEXT" /D
"_MULTILANGDLL" /D "_CRT_SECURE_NO_WARNINGS" /D "_WINDLL" /D "_MBCS" /D "_AFXDLL" /Gm
/EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /GR- /Yu"StdAfx.h" 
/Fp".\Debug\MultiLangD.pch" /Fa".\Debug\" /Fo".\Debug\" /Fd".\Debug\vc100.pdb" /Gd 
/analyze- /errorReport:queue 

在可执行项目中,我将 MultiLangD.lib 列为链接器的附加依赖项,将“Link Library Dependencies”设置为 no,将“Use Library Dependency Inputs”设置为 yes。MultiLang dll 项目未设置为可执行文件的项目依赖项。然而,在调试版本中,我收到一个错误,因为链接器找不到 MultiLang.lib。这是可执行项目的链接器命令行:

/OUT:".\Debug\WinGFApp.exe" /INCREMENTAL /NOLOGO /LIBPATH:"..\Lib"
/LIBPATH:"..\Student\lib" /LIBPATH:"C:\Program Files (x86)\Microsoft DirectX SDK (March 2009)\Lib\x86" 
"MultiLangD.lib" "datastored.lib" "shlwapi.lib" "ws2_32.lib" "MdxReadd.lib" "winmm.lib" 
"dxguid.lib" "dxerr9.lib" "dinput8.lib" "Messagingd.lib" "dtccd.lib" "Version.lib" 
"SerialTCIMD.lib" "geosrvdll.lib" "NetworkUIDMD.lib" "amp2.lib" "idmmib.lib" 
"vmfr2.lib" "d3dx9.lib" "comsuppwd.lib" "vmf_net_db.lib" "jvmfd.lib" 
/NODEFAULTLIB:"libc" /NODEFAULTLIB:"libcd" /NODEFAULTLIB:"libci" /MANIFEST 
/ManifestFile:".\Debug\WinGFApp.exe.intermediate.manifest" /ALLOWISOLATION 
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:".\Debug/CFFTInstrD.pdb" 
/SUBSYSTEM:WINDOWS
 /PGD:"C:\WorkSpaces\WorkSpace_CFFT_II_i18n\CFFT_i18n_MBCS\CFFT\Instructor\Debug\WinGFApp.pg
d" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE 

这是编译器命令行:

/I"." /I"..\Instructor\csw" /I"..\Instructor\CFFTInstr" /I"..\Student\common" 
/I"..\Student\Messaging" /I"..\Student\geotrans" /I"..\SerialTcim" /I"..\AudioServer" 
/I"..\NetworkUIDM\UIDM_Include" /I"..\NetworkUIDM\UIDM_JVMF" /I"..\NetworkUIDM" 
/I"..\Instructor\cas" /I"..\Jvmf" /I"..\Instructor\JvmfGui" /I"..\Instructor\JvmfCff" 
/I"..\NLOS" /I"C:\Program Files (x86)\Microsoft DirectX SDK (March 2009)\Include" /Zi 
/nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "NO_MSGS" /D 
"INSTRUCTOR" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES" 
/D "_CRT_NONSTDC_NO_DEPRECATE" /D "_VC80_UPGRADE=0x0600" /D "_MBCS" /Gm- /EHsc /RTC1 
/MTd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yu"stdafx.h" /Fp".\Debug/WinGFApp.pch" 
/Fa".\Debug/" /Fo".\Debug/" /Fd".\Debug/" /FR".\Debug\" /Gd /analyze-/errorReport:queue 

当我在 np++ 中打开 .vcxproj 文件并搜索 MultiLang.lib 时,它仅在发布版本中显示为依赖项,而在调试版本设置中列出了 MultiLangD.lib。这是 .vcxproj 文件中的调试设置 ItemDefinitionGroup 节点:

</ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Midl>
  <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  <MkTypLibCompatible>true</MkTypLibCompatible>
  <SuppressStartupBanner>true</SuppressStartupBanner>
  <TargetEnvironment>Win32</TargetEnvironment>
  <TypeLibraryName>.\Debug/WinGFApp.tlb</TypeLibraryName>
  <HeaderFileName>
  </HeaderFileName>
</Midl>
<ClCompile>
  <Optimization>Disabled</Optimization>
  <AdditionalIncludeDirectories>.;..\Instructor\csw;..\Instructor\CFFTInstr;..\Student\common;..\Student\Messaging;..\Student\geotrans;..\SerialTcim;..\AudioServer;..\NetworkUIDM\UIDM_Include;..\NetworkUIDM\UIDM_JVMF;..\NetworkUIDM;..\Instructor\cas;..\Jvmf;..\Instructor\JvmfGui;..\Instructor\JvmfCff;..\NLOS;C:\Program Files %28x86%29\Microsoft DirectX SDK %28March 2009%29\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
  <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;NO_MSGS;INSTRUCTOR;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
  <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
  <PrecompiledHeader>Use</PrecompiledHeader>
  <PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
  <PrecompiledHeaderOutputFile>.\Debug/WinGFApp.pch</PrecompiledHeaderOutputFile>
  <AssemblerListingLocation>.\Debug/</AssemblerListingLocation>
  <ObjectFileName>.\Debug/</ObjectFileName>
  <ProgramDataBaseFileName>.\Debug/</ProgramDataBaseFileName>
  <BrowseInformation>true</BrowseInformation>
  <WarningLevel>Level3</WarningLevel>
  <SuppressStartupBanner>true</SuppressStartupBanner>
  <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
  <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  <Culture>0x0409</Culture>
</ResourceCompile>
<Link>
  <AdditionalDependencies>MultiLangD.lib;datastored.lib;shlwapi.lib;ws2_32.lib;MdxReadd.lib;winmm.lib;dxguid.lib;dxerr9.lib;dinput8.lib;Messagingd.lib;dtccd.lib;Version.lib;SerialTCIMD.lib;geosrvdll.lib;NetworkUIDMD.lib;amp2.lib;idmmib.lib;vmfr2.lib;d3dx9.lib;comsuppwd.lib;vmf_net_db.lib;jvmfd.lib;%(AdditionalDependencies)</AdditionalDependencies>
  <SuppressStartupBanner>true</SuppressStartupBanner>
  <AdditionalLibraryDirectories>..\Lib;..\Student\lib;C:\Program Files %28x86%29\Microsoft DirectX SDK %28March 2009%29\Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
  <IgnoreSpecificDefaultLibraries>libc;libcd;libci;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
  <GenerateDebugInformation>true</GenerateDebugInformation>
  <ProgramDatabaseFile>.\Debug/CFFTInstrD.pdb</ProgramDatabaseFile>
  <SubSystem>Windows</SubSystem>
  <TargetMachine>MachineX86</TargetMachine>
</Link>
<Bscmake>
  <SuppressStartupBanner>true</SuppressStartupBanner>
  <OutputFile>Debug/CFFTInstrD.bsc</OutputFile>
</Bscmake>
<PostBuildEvent>
  <Message>Copy Executable</Message>
  <Command>if not exist ..\exec mkdir ..\exec
    copy debug\WinGFApp.exe ..\exec\CFFTInstrD.exe
  </Command>
</PostBuildEvent>
<ProjectReference />
<ProjectReference>
  <UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
  <LinkLibraryDependencies>false</LinkLibraryDependencies>
</ProjectReference>
</ItemDefinitionGroup>

不幸的是,生成的所有可执行文件和 dll 都作为构建后事件复制到一个目录中,因此我必须遵循“附加 D”命名约定以避免覆盖来自其他构建的工件。我不确定为什么构建中的其他 dll 项目都没有这个问题。我显然在这里遗漏了一些东西,但无法弄清楚它是什么。有人可以告诉我我做错了什么以及如何做到这一点。谢谢。

编辑 我忘了提到我还尝试在 Common Properties->Framework and References 中添加对项目的引用。

参考设置

此外,在编译过程中,我看到Automatically linking with MultiLang.lib滚动。

4

1 回答 1

0

好的,我得到它的工作。我删除了引用并将 Linker->General->Ignore Import Library 设置为 Yes。我将其他所有内容保持不变,现在它可以编译和链接了。

于 2013-02-26T17:05:22.200 回答