views:

1217

answers:

2

Can you suggest what factors can cause an C++ Builder's 2009 linker error "Unresolved external '__fastcall System::TObject::NewInstance(System::TMetaClass *)' referenced from XXX.obj"?

We have a set of Delphi files (pas) and set of C++ Builder files (hpp and obj), which was generated from these pas files.

Set of files is copied to another machine. Both machine has the very same C++ Builder 2009 version with the same updates (latest: 3+4) installed.

When I create an empty VCL application in C++ Builder on other machine and include one obj file from this set to the active project, I get the above mentioned error at linking stage.

The strange things about this error are:

  1. This error can be reproduced not on every machine or C++ Builder installation (I've checked at least 5 of them).
  2. If you remove obj-file and instead add corresponding pas file to the project - the error will dissappear.
  3. But if you remove pas-file and include obj-file again - there will be no error.
  4. None of the obj of pas files gets modified in the process. I.e. if you delete this set of files from the machine and bring them from the first machine again (where they were created) - you still will have no error.
  5. Once you do that sequence on one particular machine (include/exclude pas-file from the project) - you can not longer get this error on that machine, no matter how hard you try (move files between folders, playing with settings, etc, etc). Actually, I already have no machines, where I can reproduce this error right now :(

I do not see, how situation "after" is different from situation "before" (after/before inclusion of pas-file), so error is visible only before and not after.

The only mention of this error (or a very similar error) on the internet is this. But there is no solution. There are no "+" chars in the path nor spaces (" ").

Am I missing something? Right now it looks like C++ Builder bug to me.

Any ideas would be appreciated.

P.S. We can not use "just include pas-file" solution, as we need to deploy only hpp+obj (no pas-files) at certain machines.

A: 

Looks like if you build the project from the pas files, then a copy of the function ‘__fastcall System::TObject::NewInstance(System::TMetaClass *)’ is being defined somewhere, but not in the obj files, and linked to the binary. Once the function is defined, then the XXX.obj file finds it. So if you delete current obj files and bring obj files from another machine, the error is not seen. This is just my thought. I neither know Delphi nor have any idea about pas files or C++ Builder.

Is your project is creating dll or some kind of external libraries where System::TObject::NewInstance() function is defined and linked to the binary?

Donotalo
System::TObject::NewInstance is part of standart RTL, which is always linked in (is part of) the application. I.e. it can not be unimplemented. Project is not a DLL nor package - just a usual VCL (i.e. Win32) GUI application. Of couse, there is no such thing as redefinition of build-in RTL functions in our code.
Alexander
+1  A: 

OKay, I've found answer: the reason was some wrong IDE's or project's settings (I do not know for sure).

I have several versions of C++ Builders and Delphis installed. And for some reason C++ Builder's 2009 linker picked up wrong obj files - the ones, which should be used for another version (possible 2007).

The reason for the error was that NewInstance was changed between 2007 and 2009 versions - see here: https://forums.codegear.com/thread.jspa?messageID=161105

Alexander