Recent

Author Topic: exeinfo.pp can't take address of constant expressions  (Read 2850 times)

abtaylr

  • Full Member
  • ***
  • Posts: 107
exeinfo.pp can't take address of constant expressions
« on: November 07, 2019, 05:04:40 pm »
I am getting the error 'can't take address of constant expressions' when compiling a project. I have compiled it numerous times before and never have gotten this error.  My program is being built to use on linux varieties (I use kubuntu 19.10 64 bit). The file in question is exeinfo.pp found in the RTL/inc directory. The code from the file is:

Code: Pascal  [Select][+][-]
  1.  
  2. {$ifdef unix}
  3.  
  4.   procedure GetModuleByAddr(addr: pointer; var baseaddr: pointer; var filename : string);
  5.     begin
  6.       if assigned(UnixGetModuleByAddrHook) then
  7.         UnixGetModuleByAddrHook(addr,baseaddr,filename)
  8.       else
  9.         begin
  10.           baseaddr:=nil;
  11.           filename :=ParamStr(0);
  12.         end;
  13.     end;
  14.  
  15. {$else unix}
  16.  

In the file there is a type established for 'TExeFile=record' which has as one of its fields 'filename'. This word doesn't exist elsewhere in exeinfo.pp. From the error, it appears to me that the 'var filename : string' in the method declaration is the 'constant' causing the problem. I have tried to simply change the name in the method to 'fname', but still get the same error.  I tried adding a var section in the method with a variable f : string; then after begin setting f := filename; and changing the UnixGetModuleByAddrHook to f without success. I created a property with 'Getter and Setter' and tried passing the filename that mechanism without success. I ran through the Free Pascal reference manuals looking for a MACRO or other mechanism to disable the rule.  It has a macro or symbol -- {$checkpointer off}.  The file exeinfo.pp does have a macro or symbol reference to {$S-} , but I haven't found its meaning just yet.

I am quickly running out of options. I appreciate any suggestions . . .

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: exeinfo.pp can't take address of constant expressions
« Reply #1 on: November 07, 2019, 05:16:50 pm »
While your explanation is thorough, it might be helpful to see the error messages emitted by the compiler when you try to compile your program. 

If it isn't too much trouble, post them.

Also, what version of FPC are you using ?  Knowing that might be helpful too.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

abtaylr

  • Full Member
  • ***
  • Posts: 107
Re: exeinfo.pp can't take address of constant expressions
« Reply #2 on: November 07, 2019, 05:27:38 pm »
Error Message:
exeinfo.pp(68,55) Error: Can't take the address of constant expressions

FPC = 3.0.5 R43411
Lazarus = 2.06 R62218

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: exeinfo.pp can't take address of constant expressions
« Reply #3 on: November 07, 2019, 05:51:05 pm »
What fpc version do you use?
In my case (trunk)  line 68 is just the uses clause and that won't crash...
Specialize a type, not a var.

abtaylr

  • Full Member
  • ***
  • Posts: 107
Re: exeinfo.pp can't take address of constant expressions
« Reply #4 on: November 07, 2019, 06:03:58 pm »
FPC = 3.0.5 R43411

abtaylr

  • Full Member
  • ***
  • Posts: 107
Re: exeinfo.pp can't take address of constant expressions
« Reply #5 on: November 07, 2019, 06:36:23 pm »
I tried compiling just exeinfo.pp and it didn't crash in a Console window from command line. But when I try inside of Lazarus it still crashes in exeinfo.pp with the same message:  exeinfo.pp(68,55) Error: Can't take the address of constant expressions.

I tried in Lazarus to do just a build file for exeinfo.pp and it compiled, but when I go back to compiling the project I get the same error.
« Last Edit: November 07, 2019, 06:41:53 pm by abtaylr »

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: exeinfo.pp can't take address of constant expressions
« Reply #6 on: November 07, 2019, 06:56:09 pm »
what is your line 68 and what variables are involved?
Specialize a type, not a var.

abtaylr

  • Full Member
  • ***
  • Posts: 107
Re: exeinfo.pp can't take address of constant expressions
« Reply #7 on: November 07, 2019, 07:05:06 pm »
Code: Pascal  [Select][+][-]
  1. {$ifdef unix}
  2.  
  3.   procedure GetModuleByAddr(addr: pointer; var baseaddr: pointer; var filename : string);
  4.     begin
  5.       if assigned(UnixGetModuleByAddrHook) then
  6.         UnixGetModuleByAddrHook(addr,baseaddr,filename)                 <=========== line 68
  7.       else
  8.         begin
  9.           baseaddr:=nil;
  10.           filename :=ParamStr(0);
  11.         end;
  12.     end;
  13.              
  14.  
  15.  

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: exeinfo.pp can't take address of constant expressions
« Reply #8 on: November 07, 2019, 07:09:20 pm »
Is there a const filename anywhere else in your code?
« Last Edit: November 07, 2019, 07:13:31 pm by Thaddy »
Specialize a type, not a var.

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: exeinfo.pp can't take address of constant expressions
« Reply #9 on: November 07, 2019, 07:27:18 pm »
I tried in Lazarus to do just a build file for exeinfo.pp and it compiled, but when I go back to compiling the project I get the same error.
Do you have a call to "GetModuleByAddr" anywhere in your code ?  if you do, check the type definition of the variables you are passing in that call.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

abtaylr

  • Full Member
  • ***
  • Posts: 107
Re: exeinfo.pp can't take address of constant expressions
« Reply #10 on: November 07, 2019, 07:47:41 pm »
I found a unit that uses FileName as part of a record type, so I changed that instance, then compiled, but got the same error message.

I don't use either GetModuleByAddr or UnixGetModuleByAddrHook.  This file exeinfo.pp is getting called from some other include or unit. I have not found what unit is calling exeinfo.pp. I tried using the switch -va to get everything, but still couldn't find it.

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: exeinfo.pp can't take address of constant expressions
« Reply #11 on: November 07, 2019, 07:59:52 pm »
I found a unit that uses FileName as part of a record type, so I changed that instance, then compiled, but got the same error message.

I don't use either GetModuleByAddr or UnixGetModuleByAddrHook.  This file exeinfo.pp is getting called from some other include or unit. I have not found what unit is calling exeinfo.pp. I tried using the switch -va to get everything, but still couldn't find it.
Any chance you can post your project (full source) ?... without the code everything is a guess.  Note that since I don't have a unix/Linux environment available at this time, I won't be able to be of further assistance even if you post all the source code but, someone else may be able to help you.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

abtaylr

  • Full Member
  • ***
  • Posts: 107
Re: exeinfo.pp can't take address of constant expressions
« Reply #12 on: November 07, 2019, 08:31:00 pm »
Here is a copy of the project. It started life as a Windows project. I am transforming it into a format to be usable on different platforms with the most immediate form being linux.

It's too large in one bite . . .

abtaylr

  • Full Member
  • ***
  • Posts: 107
Re: exeinfo.pp can't take address of constant expressions
« Reply #13 on: November 07, 2019, 08:31:51 pm »
subrip-1.57.2-pt2

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: exeinfo.pp can't take address of constant expressions
« Reply #14 on: November 08, 2019, 09:49:01 am »
The question should be: why are you compiling rtl/inc/exeinfo.pp anyway? You should use the precompiled unit that belongs to FPC's distribution. And if you made local changes you should either rebuild FPC or copy the unit somewhere else.

 

TinyPortal © 2005-2018