1
votes

I'm trying to compile an old project in Borland C++ Builder 4. I have a working exe and the source files for that, therefore someone must have managed to compile it earlier. However, when I open the project, check if the project hs all the necessary files in the resources and try to compile it, I keep getting the following linker error:

[Linker Error] Unresolved external '_fastcall TMapperForm::Button1Click(System::TObject*)' referenced from ...\Unit1.obj

I can see that it cannot find an object in the library but I am not sure how to resolve it, because the obj file with the same name as the main cpp file is in the same file as the other files of the project and seems fine.

I have looked through the answers provided here for similar linker errors but none of what these have suggested worked for me. I have already tried the following:

  • Adding the .obj file to the Project Resources.
  • Trying to add pragma lines manually such as #pragma link (Unit1.obj)
  • Making sure that in Project>Options>Directories the right Include and Library paths were selected.
  • Checking if all the packages have been added.

None of this seems to work. I am fairly new to C++ and C++ Builder, so I am hoping that it is something trivial.

Has anybody seen this particular error?

1
It isn't Unit1.obj that it can't find, that is the file that is referencing the missing method. If I had to guess, I'd guess that the source code is actually missing a definition for Button1Click in the TMapperForm class. Try opening the form in the designer and double clicking on Button1. If there is an OnClick handler defined, it will take you to it in the source, and you can fix the reference to point to that method. If it doesn't have one, a Button1Click method stub will be created for you.David Dean
@DavidDean thank you SO much. There was a Button1 object defined in the header file, in the TMapperForm class, which I missed. Apparently the original developper started something adding an extra button but never used it and then left the definition in the class def.laika
That sometimes happen when you save project (or any file) and your handler code is empty. BCB optimize it out but sometimes leave the button handler call behind (especially if it was added manually) ... Also you need to be careful with the rem lines because if you remove them and optimize out function without those it could rem out 1 or two lines near that function making mess ...Spektre
@Spektre yeah it offered automatically removing some lines and I was concerned that it may delete important stuff, but it seems it's fine. Thanks for the tip though, it's not easy to find people who know BCB 4.laika
@laika BCB3,4,5,6 and BDS2006 are almost the same IDEs all have its own quirks if you know them you can build anything inside even very complex stuff without problems my favorite is BCB5 and BDS2006 the worst is BCB6 (too many issues and bugs)Spektre

1 Answers

0
votes

The error was caused by a missing handler or more precisely a handler containing nothing.

While the handler for the button contained nothing, the TMapperForm class still included the definitions for an extra button named Button1 but it was not used. Commenting out the method and the declaration in the TMapperForm class (in the header file for Unit1) along with the handler in the C++ file resolved the problem.