Recent

Author Topic: External variable compilation error  (Read 3527 times)

Roland57

  • Sr. Member
  • ****
  • Posts: 419
    • msegui.net
External variable compilation error
« 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?


« Last Edit: October 29, 2020, 07:55:22 pm by Roland57 »
My projects are on Gitlab and on Codeberg.

Roland57

  • Sr. Member
  • ****
  • Posts: 419
    • msegui.net
Re: External variable compilation error
« Reply #1 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}
My projects are on Gitlab and on Codeberg.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11382
  • FPC developer.
Re: External variable compilation error
« Reply #2 on: October 29, 2020, 08:20:50 pm »
look up cvar in the documentation

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: External variable compilation error
« Reply #3 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.
« Last Edit: October 29, 2020, 11:29:39 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Roland57

  • Sr. Member
  • ****
  • Posts: 419
    • msegui.net
Re: External variable compilation error
« Reply #4 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.  :-\
My projects are on Gitlab and on Codeberg.

Roland57

  • Sr. Member
  • ****
  • Posts: 419
    • msegui.net
Re: External variable compilation error
« Reply #5 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
My projects are on Gitlab and on Codeberg.

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: External variable compilation error
« Reply #6 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
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Roland57

  • Sr. Member
  • ****
  • Posts: 419
    • msegui.net
Re: External variable compilation error
« Reply #7 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'

 :-\
My projects are on Gitlab and on Codeberg.

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: External variable compilation error
« Reply #8 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
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

 

TinyPortal © 2005-2018