[英]F2051 Unit was compiled with a different version (again)
( Warning: long read . This question references a lof of the other questions about F2051) (警告:长读。这个问题引用了关于 F2051 的其他一些问题)
We have a folder named PatchLibs in our source tree in which we put modified files of third party sources.我们的源代码树中有一个名为 PatchLibs 的文件夹,我们在其中放置了第三方源代码的修改文件。
This is in the project search path: ..\Skin;..\PatchLibs
这是在项目搜索路径中:
..\Skin;..\PatchLibs
I copied the file dxBar.pas from DevExpress controls into Patchlibs and modified some code in the implementation section only .我将文件 dxBar.pas 从 DevExpress 控件复制到 Patchlibs 中,并仅在实现部分修改了一些代码。
Now, when building (with all local .dcu
files deleted and a 'Cleanup') I get the infamous:现在,在构建时(删除了所有本地
.dcu
文件并进行了“清理”),我得到了臭名昭著的:
[dcc32 Fatal Error] F2051 Unit cxBarEditItem was compiled with a different version of dxBar.TdxBarItemControl.GetItem
It doesn't refer to a line of code.它不是指一行代码。 I get the message when it starts compiling.
我在开始编译时收到消息。
Configuration:配置:
New Delphi and DevExpress versions installed in a new VM;在新 VM 中安装新的 Delphi 和 DevExpress 版本; copied the program source tree.
复制了程序源代码树。
C:\DelphiLibs\DevExpress\VCL\Library\RS27
is in the 32bit library path C:\DelphiLibs\DevExpress\VCL\Library\RS27
在32位库路径
That folder contains all the DevExpress dcu's, notably cxBarEditItem.dcu
and dxBar.dcu
该文件夹包含所有 DevExpress dcu,特别是
cxBarEditItem.dcu
和dxBar.dcu
(So does the $(DXVCL)\Library\RS27\Win64
library path, but this is a Win32 app) (
$(DXVCL)\Library\RS27\Win64
库路径也是如此,但这是一个 Win32 应用程序)
There are no other occurrences of cxBarEditItem.dcu
anywhere;任何地方都没有其他
cxBarEditItem.dcu
出现; dcBar.pas
and cxBarEditItem.pas
are in c:\DelphiLibs\DevExpress\VCL\ExpressBars\Sources\
dcBar.pas
和cxBarEditItem.pas
位于c:\DelphiLibs\DevExpress\VCL\ExpressBars\Sources\
(I even scanned the disk for all cx*.* and dx*.* files). (我什至扫描了磁盘上的所有 cx*.* 和 dx*.* 文件)。
That source folder is also present in the Browsing path ( $(DXVCL)\ExpressBars\Sources
)该源文件夹也存在于浏览路径中(
$(DXVCL)\ExpressBars\Sources
)
These are just units (no corresponding .dfm
files)这些只是单位(没有相应
.dfm
文件)
There are other modified DevExpress files in Patchlibs that I have no issues with; Patchlibs 中还有其他修改过的 DevExpress 文件,我对此没有任何问题; and there are some more with which I have the same issue (not just
dxBar
).还有一些我有同样的问题(不仅仅是
dxBar
)。
Project is set up to place .dcu
files next to their .pas
sources ( Unit Output Directory is blank)项目设置为将
.dcu
文件放在其.pas
源旁边(单元 Output 目录为空白)
No DevExpress files are part of the project没有 DevExpress 文件是项目的一部分
Other source files in the project have changed项目中的其他源文件已更改
If I pull a copy of cxBarEditItem.pas
into Patchlibs, the error only just propagates to another unit (repeatedly).如果我将
cxBarEditItem.pas
的副本拉入 Patchlibs,则错误只会传播到另一个单元(重复)。
Despite having read many answers (Notable SO question: Why are my units "compiled with a different version" of my own files? ) I simply do not understand why the error occurs and how to fix it this time .尽管已经阅读了很多答案(值得注意的 SO 问题: 为什么我的单位是“用不同版本编译的”我自己的文件? )我只是不明白为什么会发生错误以及这次如何修复它。
cxBarEditItem.pas
has dxBar
in its interface Uses section, and cxBarEditItem
is in my Uses clauses, but why would it want to recompile? cxBarEditItem.pas
在其接口 Uses 部分中有dxBar
,而cxBarEditItem
在我的 Uses 子句中,但它为什么要重新编译?
I can of course start adding the DevExpress source code directories into the Search Path, but there are a lot of those and this will result in .dcu
files in them as well.我当然可以开始将 DevExpress 源代码目录添加到搜索路径中,但是其中有很多,这也会导致
.dcu
文件在其中。
I prefer not to do that because it masks the actual problem and this was not necessary in the previous Delphi/DevExpress setup :我不想这样做,因为它掩盖了实际问题,而这在以前的 Delphi/DevExpress 设置中不是必需的:
32 bits library path in earlier Delphi 10.3:早期 Delphi 10.3 中的 32 位库路径:
c:\DelphiLibs\CompanyName
c:\DelphiLibs\CompanyName\TTLib
c:\DelphiLibs\CompanyName\DataFox
C:\DelphiLibs\RBuilder\Source
$(BDSLIB)\$(Platform)\release
$(BDSUSERDIR)\Imports
$(BDS)\Imports
$(BDSCOMMONDIR)\Dcp
$(BDS)\include
c:\delphilibs\multilizer\localizationcomponentsxex_x86\packages\full\bplxe\20.0
C:\DelphiLibs\Multilizer\LocalizationComponentsXEx_x86
c:\delphilibs\pascal script\dcu\d25\win32
C:\DelphiLibs\Pascal Script\Source
C:\DelphiLibs\RemObjects Software\RemObjects SDK for Delphi\Dcu\D26\Win32
C:\DelphiLibs\RemObjects Software\RemObjects SDK for Delphi\Source
C:\DelphiLibs\RemObjects Software\RemObjects SDK for Delphi\Source\DataSnap
C:\DelphiLibs\RemObjects Software\RemObjects SDK for Delphi\Source\ZLib
C:\DelphiLibs\RemObjects Software\RemObjects SDK for Delphi\Source\Synapse
$(Everwood)\Bin
C:\DelphiLibs\Scalabium\SMExport\Sources
C:\DelphiLibs\Scalabium\SMImport\Sources
C:\DelphiLibs\Cooltray
C:\DelphiLibs\PlusMemo\
C:\Delphilibs\RBuilder\Lib\Win32
C:\DelphiLibs\PlusMemo
C:\DelphiLibs\IPWorks 2020 Delphi Edition\pas
C:\DelphiLibs\IPWorks Auth 2020 Delphi Edition\pas
C:\DelphiLibs\IPWorks Encrypt 2020 Delphi Edition\pas
C:\DelphiLibs\IPWorks SSH 2020 Delphi Edition\pas
C:\DelphiLibs\IPWorks ZIP 2020 Delphi Edition\pas
C:\DelphiLibs\VirtualUI\dev\Delphi
c:\DelphiLibs\CEF4Delphi-master\source\
$(DXVCL)\Library\RS26
32 bits library path in Delphi 10.4: Delphi 10.4 中的 32 位库路径:
c:\DelphiLibs\CompanyName
c:\DelphiLibs\CompanyName\TTLib
c:\DelphiLibs\CompanyName\DataFox
C:\DelphiLibs\RBuilder\Source
c:\program files (x86)\embarcadero\studio\21.0\lib\Win32\release
C:\Users\Jan\Documents\Embarcadero\Studio\21.0\Imports
c:\program files (x86)\embarcadero\studio\21.0\Imports
C:\Users\Public\Documents\Embarcadero\Studio\21.0\Dcp
c:\program files (x86)\embarcadero\studio\21.0\include
c:\delphilibs\plusmemo
C:\DelphiLibs\RBuilder\Lib\Win32
C:\DelphiLibs\Multilizer\LocalizationComponentsXEx_x86
C:\DelphiLibs\PlusMemo
C:\DelphiLibs\Pascal Script\Source
C:\DelphiLibs\Scalabium\SMExport\Sources
C:\DelphiLibs\Scalabium\SMImport\Sources
C:\DelphiLibs\Cooltray
C:\DelphiLibs\VirtualUI\dev\Delphi
C:\DelphiLibs\nSoftware\IPWorks 2020 Delphi Edition\pas
C:\DelphiLibs\nSoftware\IPWorks Auth 2020 Delphi Edition\pas
C:\DelphiLibs\nSoftware\IPWorks SSH 2020 Delphi Edition\pas
C:\DelphiLibs\nSoftware\IPWorks ZIP 2020 Delphi Edition\pas
C:\DelphiLibs\nSoftware\IPWorks Encrypt 2020 Delphi Edition\pas
C:\DelphiLibs\RemObjects Software\RemObjects SDK for Delphi\Dcu\D27\Win32
C:\DelphiLibs\RemObjects Software\RemObjects SDK for Delphi\Source
C:\DelphiLibs\RemObjects Software\RemObjects SDK for Delphi\Source\DataSnap
C:\DelphiLibs\RemObjects Software\RemObjects SDK for Delphi\Source\Grijjy
C:\DelphiLibs\RemObjects Software\RemObjects SDK for Delphi\Source\Synapse
C:\DelphiLibs\RemObjects Software\RemObjects SDK for Delphi\Source\ZLib
C:\Program Files (x86)\RemObjects Software\Everwood\Bin
C:\DelphiLibs\SQLDirect\Source
C:\DelphiLibs\CEF4Delphi-master\source
C:\DelphiLibs\DevExpress\VCL\Library\RS27
Moving that last one up or down or changing it to $(DXVCL)\Library\RS27
did not help向上或向下移动最后一个或将其更改为
$(DXVCL)\Library\RS27
没有帮助
Those 5 Embarcadero lines look weird (see this SO question , I replaced them with their old counterparts ( and reported to Embarcadero ); no change in the issue.这 5 条 Embarcadero 线看起来很奇怪(请参阅这个 SO question ,我用旧的对应物替换了它们(并向 Embarcadero 报告);问题没有变化。
Additional research/failed attempt额外的研究/失败的尝试
Ian Boyd had a very a similar problem way down in 2014伊恩博伊德在 2014 年遇到了一个非常相似的问题
F2051: Unit %s was compiled with a different version of %s F2051: 单元 %s 是用不同版本的 %s 编译的
Suggestions there were RTTI settings or compiler options.建议有 RTTI 设置或编译器选项。
Based on David's answer there, I decided to give that a try.根据大卫在那里的回答,我决定试一试。 My situation was slightly different: I had to try to find out what compiler settings were used when building the DevEx code and insert those into the top of my modified
dxBar.pas
.我的情况略有不同:我必须尝试找出在构建 DevEx 代码时使用了哪些编译器设置,并将它们插入到我修改后的
dxBar.pas
的顶部。
I noticed that there are two .dproj
files in Packages
subfolders in the DevExpress installation: cxLibraryRS27.dproj
and dxBarRS27.dproj
(requiring cxLibraryRS27
BTW)我注意到 DevExpress 安装的
Packages
子文件夹中有两个.dproj
文件: cxLibraryRS27.dproj
和dxBarRS27.dproj
(需要cxLibraryRS27
BTW)
By setting all compiler options in a test project to non-defaults and comparing that .dproj
to one with all the defaults I was able to understand (most of) the relation between UI option settings and the .dproj
contents.通过将测试项目中的所有编译器选项设置为非默认值并将
.dproj
与所有默认值进行比较,我能够理解(大部分)UI 选项设置和.dproj
内容之间的关系。
I then compared their cxLibraryRS27.dproj
settings against those from our project and found the following differences (irrelevant lines removed):然后,我将他们的
cxLibraryRS27.dproj
设置与我们项目中的设置进行了比较,发现了以下差异(删除了不相关的行):
They had this extra:他们有这个额外的:
<PropertyGroup Condition="'$(Base)'!=''">
<DCC_E>false</DCC_E> No idea what these are...
<DCC_F>false</DCC_F>
<DCC_K>false</DCC_K>
<DCC_N>false</DCC_N>
<DCC_S>false</DCC_S>
<DCC_DebugInformation>0</DCC_DebugInformation>
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
<DCC_AssertionsAtRuntime>false</DCC_AssertionsAtRuntime>
<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
We had this extra:我们有这个额外的:
<PropertyGroup Condition="'$(Cfg_1)'!=''">
(this is the one with <DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>)
<DCC_IntegerOverflowCheck>True</DCC_IntegerOverflowCheck>
<DCC_RangeChecking>True</DCC_RangeChecking>
<DCC_SYMBOL_DEPRECATED>False</DCC_SYMBOL_DEPRECATED>
<DCC_SYMBOL_LIBRARY>False</DCC_SYMBOL_LIBRARY>
<DCC_SYMBOL_PLATFORM>False</DCC_SYMBOL_PLATFORM>
<DCC_UNIT_LIBRARY>False</DCC_UNIT_LIBRARY>
<DCC_UNIT_PLATFORM>False</DCC_UNIT_PLATFORM>
<DCC_UNIT_DEPRECATED>False</DCC_UNIT_DEPRECATED>
<PropertyGroup Condition="'$(Cfg_1_Win32)'!=''">
<DCC_COMBINING_SIGNED_UNSIGNED>false</DCC_COMBINING_SIGNED_UNSIGNED>
<DCC_COMPARING_SIGNED_UNSIGNED>false</DCC_COMPARING_SIGNED_UNSIGNED>
and和
<PropertyGroup Condition="'$(Cfg_2)'!=''">
(this is the one with <DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>)
<DCC_DebugInfoInExe>true</DCC_DebugInfoInExe>
<DCC_DebugDCUs>true</DCC_DebugDCUs>
<DCC_WriteableConstants>True</DCC_WriteableConstants>
<DCC_IntegerOverflowCheck>True</DCC_IntegerOverflowCheck>
<DCC_RangeChecking>True</DCC_RangeChecking>
<DCC_SymbolReferenceInfo>2</DCC_SymbolReferenceInfo>
<DCC_StackSize>16384,9437184</DCC_StackSize>
<DCC_SYMBOL_DEPRECATED>False</DCC_SYMBOL_DEPRECATED>
<DCC_SYMBOL_LIBRARY>False</DCC_SYMBOL_LIBRARY>
<DCC_SYMBOL_PLATFORM>False</DCC_SYMBOL_PLATFORM>
<DCC_UNIT_LIBRARY>False</DCC_UNIT_LIBRARY>
<DCC_UNIT_PLATFORM>False</DCC_UNIT_PLATFORM>
<DCC_UNIT_DEPRECATED>False</DCC_UNIT_DEPRECATED>
<DCC_COMPARING_SIGNED_UNSIGNED>False</DCC_COMPARING_SIGNED_UNSIGNED>
<DCC_COMBINING_SIGNED_UNSIGNED>False</DCC_COMBINING_SIGNED_UNSIGNED>
and they did not have this PropertyGroup他们没有这个 PropertyGroup
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<VerInfo_IncludeVerInfo>false</VerInfo_IncludeVerInfo>
<DCC_DebugInfoInExe>false</DCC_DebugInfoInExe>
<ILINK_FullDebugInfo>true</ILINK_FullDebugInfo>
<BCC_SourceDebuggingOn>true</BCC_SourceDebuggingOn>
<BCC_DebugLineNumbers>true</BCC_DebugLineNumbers>
<BT_BuildType>Debug</BT_BuildType>
<DCC_ImportedDataReferences>false</DCC_ImportedDataReferences>
<DCC_DebugDCUs>false</DCC_DebugDCUs>
</PropertyGroup>
Going through these I think these are the settings they have differently and that may influence the generated .dcu
files:通过这些,我认为这些是它们不同的设置,可能会影响生成的
.dcu
文件:
Range checking off {$R-}范围检查 {$R-}
Overflow checking off {$Q-}溢出检查 {$Q-}
Local debugs symbols off {$D-}本地调试符号关闭 {$D-}
Runtime assertions off {$C-}关闭 {$C-} 的运行时断言
Symbol reference info off {$L-}符号参考信息关闭 {$L-}
Writeable constants off {$J-}关闭 {$J-} 的可写常量
Debug info in exe off {$Y-} exe 中的调试信息关闭 {$Y-}
So I put this at the top of dxBar.pas
:所以我把它放在
dxBar.pas
的顶部:
{$C-,D-,J-,L-,Q-,R-,Y-} {$C-,D-,J-,L-,Q-,R-,Y-}
Nope, no success...不,没有成功...
I did not read entirely but immediately checked the DevExpress sources when I saw the compile error.我没有完整阅读,但是当我看到编译错误时立即检查了 DevExpress 源代码。
This is very much related to the fact that TdxBarItemControl.GetItem
is marked as inline
.这与
TdxBarItemControl.GetItem
被标记为inline
的事实非常相关。 When inline
or generics (they behave similar) are involved it often is required that if you change such a unit also any other unit using this one has to be recompiled as well.当涉及
inline
或 generics(它们的行为相似)时,通常需要如果您更改这样的单元,则还必须重新编译使用该单元的任何其他单元。
Suggestion based on experience (we also use DevExpress with custom modifications):基于经验的建议(我们也使用带有自定义修改的 DevExpress):
Put them into version control (also the binaries. git lfs ftw) and when you change any of the source just recompile and commit any changes.将它们放入版本控制(也是二进制文件。git lfs ftw),当您更改任何源时,只需重新编译并提交任何更改。 Keep this repository seperate from your own source repository but tag/branch it identical to your source repository.
将此存储库与您自己的源存储库分开,但将其标记/分支与您的源存储库相同。 Changing between versions then also will be a no brainer.
然后在版本之间进行更改也将是不费吹灰之力。
I am not convinced it is about compiler options.我不相信它与编译器选项有关。 I guess there may be a missing
cxBarEditItem.pas
file.我猜可能缺少
cxBarEditItem.pas
文件。 Or there is an old cxBarEditItem.dcu
somewhere in your linking path.或者在您的链接路径中某处有一个旧的
cxBarEditItem.dcu
。 So the compiler is confused.所以编译器很困惑。
Try to clean up the component sources, to have only .pas
files and no .dcu
, and try to recompile again.尝试清理组件源,只有
.pas
文件而没有.dcu
,然后再次尝试重新编译。
If it is not enough, then maybe this is a problem with the components .inc
files, and incompatible options.如果还不够,那么这可能是组件
.inc
文件的问题,以及不兼容的选项。 Don't try to modify the third-party component source code, you will most probably break something.不要试图修改第三方组件源代码,你很可能会破坏一些东西。
I just had the same problem, searched it, found this and for me the answer was this: I forgot to add a .pas
file for a unit to the .dpr
but still had a .dcu
for it lying around from another build.我只是遇到了同样的问题,搜索了它,找到了这个,对我来说答案是这样的:我忘记将一个单元的
.pas
文件添加到.dpr
但仍然有一个来自另一个构建的.dcu
。
I had to add the file to the .dpr
and everything worked again.我不得不将文件添加到
.dpr
并且一切都再次正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.