The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,259 other subscribers

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:

  1. the documentation on E2201 Need imported data reference ($G) to access ‘%s’ from unit ‘%s’ isn’t very well written
  2. [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

2 Responses to “Confusing Delphi message: [DCC Error] E2201 Need imported data reference ($G) to access ‘VarCopyProc’ from unit ‘XXX’”

  1. 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

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.