Delphi Error – E2172 Necessary library helper function was eliminated by linker (%s)

Delphi Compiler Error

E2172 Necessary library helper function was eliminated by linker (%s)

Reason for the Error & Solution

The integrated debugger is attempting to use some of the compiler helper functions to perform the requested evaluate. The linker, on the other hand, determined that the helper function was not actually used by the program and it did not link it into the program.

  1. Create a new application.
  2. Place a button on the form.
  3. Double click the button to be taken to the ‘click’ method.
  4. Add a global variable, ‘v’, of type String to the interface section.
  5. Add a global variable, ‘p’, of type PChar to the interface section.

The click method should read as:

  1. procedure TForm1.Button1Click(Sender: TObject); begin v := ‘Initialized’; p := NIL; v := ‘Abid’; end;
  2. Set a breakpoint on the second assignment to ‘v’.
  3. Compile and run the application.
  4. Press the button.
  5. After the breakpoint is reached, open the evaluator (Run|Evaluate/Watch).
  6. Evaluate ‘v’.
  7. Move the cursor to the ‘New Value’ box.
  8. Type in ‘p’.
  9. Choose Modify.

The compiler uses a special function to copy a PChar to a String. In order to reduce the size of the produced executable, if that special function is not used by the program, it is not linked in. In this case, there is no assignment of a PChar to a String, so it is eliminated by the linker.

  procedure TForm1.Button1Click(Sender: TObject);
  begin
       v := 'Initialized';
       p := NIL;
       v := 'Abid';
       v := p;
  end;

Adding the extra assignment of a PChar to a String will ensure that the linker includes the desired procedure in the program. Encountering this error during a debugging session is an indicator that you are using some language/environment functionality that was not needed in the original program.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...