Lazarus

Free Pascal => Unix => Topic started by: Roland57 on October 29, 2020, 07:51:53 pm

Title: External variable compilation error
Post by: Roland57 on October 29, 2020, 07:51:53 pm
Hello!

I try to compile a program that I didn't written. I have a problem with thee two lines:

Code: Pascal  [Select][+][-]
  1. var
  2.   stdout: pointer; {$ifdef linux}external libc;{$endif}
  3.   stdin: pointer; {$ifdef linux}external libc;{$endif}

I get this error message, that I don't know how to solve:
Quote
uSystem.pas(45,43) Fatal: Syntax error, ":" expected but "identifier LIBC" found

Would someone have a suggestion?


Title: Re: External variable compilation error
Post by: Roland57 on October 29, 2020, 08:04:07 pm
I have just seen that there is an *.inc with this:

Code: Pascal  [Select][+][-]
  1. {$ifdef linux}
  2.   const
  3.     libc = 'c';
  4.     fmt64 = 'll';
  5. {$else}
Title: Re: External variable compilation error
Post by: marcov on October 29, 2020, 08:20:50 pm
look up cvar in the documentation
Title: Re: External variable compilation error
Post by: Fred vS on October 29, 2020, 08:22:19 pm
Hello Roland.

This compiles ok here:

Code: Pascal  [Select][+][-]
  1. program testvar;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. var
  6.   stdin: pointer; external 'libc.so.6';
  7.   stdout: pointer; external 'libc.so.6';
  8.  
  9. begin
  10. end.
Title: Re: External variable compilation error
Post by: Roland57 on October 29, 2020, 08:39:04 pm
look up cvar in the documentation

Thank you for your answer.

I tried this:
Code: Pascal  [Select][+][-]
  1. var
  2.   hConsole: THandle;
  3.   stdout: pointer; {$ifdef linux}cvar; external libc;{$endif}
  4.   stdin: pointer; {$ifdef linux}cvar; external libc;{$endif}

and also this:
Code: Pascal  [Select][+][-]
  1. var
  2.   hConsole: THandle;
  3.   stdout: pointer; {$ifdef linux}cvar; external;{$endif}
  4.   stdin: pointer; {$ifdef linux}cvar; external;{$endif}

without success.  :-\
Title: Re: External variable compilation error
Post by: Roland57 on October 29, 2020, 08:40:26 pm
Hello Roland.

This compiles ok here:

Code: Pascal  [Select][+][-]
  1. program testvar;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. var
  6.   stdin: pointer; external 'libc';
  7.   stdout: pointer; external 'libc';
  8.  
  9. begin
  10. end.

Weird. Here it doesn't compile.

Here are my options:
Code: Text  [Select][+][-]
  1. fpc -FcUTF8 -B -Mobjfpc -Sh -FUunits OpenCritter.dpr -o./critter32 -dDEBUG -ghl
Title: Re: External variable compilation error
Post by: Fred vS on October 29, 2020, 08:46:49 pm
Code: Bash  [Select][+][-]
  1. fred@fiens ~>fpc -B testvar.pas

Quote
Free Pascal Compiler version 3.2.1[2020/08/24] for x86_64
Copyright (c) 1993-2020 by Florian Klaempfl & Others.
Target OS: Linux for x86-64
Compiling testvar.pas
testvar.pas(6,3) Note: Local variable "stdin" not used
testvar.pas(7,3) Note: Local variable "stdout" not used
Linking testvar
10 lines compiled, 0.1 sec
2 note(s) issued
Title: Re: External variable compilation error
Post by: Roland57 on October 29, 2020, 08:54:51 pm
OK, Fred, you are right. There was a {$mode delphi } in the head of the file. After I removed it, it compiles.

But maybe is it rather:

Code: Pascal  [Select][+][-]
  1. external 'c'

 :-\
Title: Re: External variable compilation error
Post by: Fred vS on October 29, 2020, 08:59:44 pm
But maybe is it rather:

Code: Pascal  [Select][+][-]
  1. external 'c'

 :-\

If you want, it is the **great** feature of fpc, to auto-add 'lib' prefix (and auto-cut the 'so number').

;-°

Fre;D
TinyPortal © 2005-2018