Confusing Delphi message: [DCC Error] E2201 Need imported data reference ($G) to access ‘VarCopyProc’ from unit ‘XXX’
Posted by jpluimers on 2013/03/20
I recently had an error like this when building with packages:
[DCC Error] E2201 Need imported data reference ($G) to access 'VarCopyProc' from unit 'SynCommons'
It was a bit hard to find good information about this error, mainly because of two reasons:
- the documentation on E2201 Need imported data reference ($G) to access ‘%s’ from unit ‘%s’ isn’t very well written
- [dcc error] e2201 need imported data reference ($g) to access ‘varcopyproc’ from unit – Google Search doesn’t yield very good answers
Finally, it was the FastMM and D2007 – Delphi Language BASM – BorlandTalk.com thread pointing me to Hallvard’s Blog: Hack#13: Access globals faster ($ImportedData).
That explained the error was caused by:
- VarCopyProc being a variable in one package
- VarCopyProc access being needed from the package that failed to compile
- Not having
{$G+}
or{$IMPORTEDDATA ON}
in the failing package would prevent that access
Somehow that does not work for all cases. Apparently, the VarCopyProc
isn’t exported from the Delphi RTL as that package is compiled in the $G- state.
So I had to add the USEPACKAGES
define to the conditional defines list, which forces the SynCommons
to use the standard version of the RecordCopy
method in stead of a highly optimized one that calls VarCopyProc
.
–jeroen
abouchez said
About the USEPACKAGES conditional, it is indeed defined in SynCommons.inc include file. See http://synopse.info/fossil/info/7a843d95e8
The issue comes from the fact that this VarCopyProc is not available from asm blocks, AFAIR.
See http://synopse.info/forum/viewtopic.php?id=539
jpluimers said
I don’t have access to this project any more, but from what I recall you are right.