Recent

Author Topic: Don't understand compiler linking process  (Read 319 times)

dculp

  • Full Member
  • ***
  • Posts: 129
Don't understand compiler linking process
« on: September 15, 2021, 03:17:52 pm »
I have the following demo code --

Code: Pascal  [Select][+][-]
  1. program Demo_10a;
  2.  
  3. uses
  4.    windows in 'D:\Lazarus_32bit_2.0.x\fpc\3.0.4\source\rtl\win32\windows.pp';
  5.  
  6. begin
  7. writeln('Debug_str = ', Debug_str); // Debug_str is declared in windows.pp
  8. readln;
  9. end.
  10.  

In windows.pp I try to induce a deliberate compiler error just to make sure that windows.pp is indeed being compiled --

Code: Pascal  [Select][+][-]
  1. unit windows;
  2. Induce deliberate compiler failure here !!!
  3. // Remainder of windows unit follows ...
  4.  

When I build, Lazarus should produce an error when it comes to the line "Induce deliberate compiler failure here !!!". However, the compiler seems to bypass windows.pp and instead causes an error in the main program -- "Demo_10a.PAS(10,25) Error: Identifier not found "Debug_str".

However, if I copy windows.pp to the folder where Demo_10a is located then a compiler error is produced, as expected -- "windows.pp(16,1) Fatal: Syntax error, "INTERFACE" expected but "identifier INDUCE" found". This makes me think that something is wrong with the statement "uses windows in 'D:\Lazarus_32bit_2.0.x\fpc\3.0.4\source\rtl\win32\windows.pp';". However, if this statement isn't correct then why doesn't the compiler give an error at that point, something like "windows unit not found"? (There is a windows.ppu in "D:\Lazarus_32bit_2.0.x\fpc\3.0.4\units\i386-win32\rtl\" so perhaps the compiler is using that instead. However, that file doesn't have the current date.)

Lazarus 1.6.4
FPC 3.0.2
Windows 10 Pro

Thanks,
Don C.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 9527
  • FPC developer.
Re: Don't understand compiler linking process
« Reply #1 on: September 15, 2021, 04:26:49 pm »
Free Pascal uses precompiled units that are in FPC's directory units/ hierarchy.
This is what makes the compilation somewhat fast.

In general it is not recommended to experiment with this because if you change unit windows, all units using unit windows also need to be compiled.

So either rebuild FPC ( and lazarus if you use it), or use the precompiled units, and don't have anything (Unit path or ... IN ... or -Fu commandline parameters) point into the FPC sources.

 

TinyPortal © 2005-2018