[Lazarus] Cannot compile console application, why?
Bo Berglund
bo.berglund at gmail.com
Mon Jul 6 00:49:26 CEST 2020
I have created a test application using Lazarus 2.0.8 and fpc 3.0.4 on
Windows 10.
The purpose is to check some Indy10 TCP communications items before
putting them into the main project.
So I have created a new project as a console application and
implemented my test Indy code.
When I use "Run/Quick compile" it reports no errors so then I tried to
use "Run/Compile" in order to get an executable but now it shows a
large number of errors of this kind:
IndyTest.lpr(76,1) Error: Undefined symbol: WSRegisterMenuItem
I have even gone into the project options/compiler options/additions
and overrides and set the widgetset to nongui (as I have been taught
before).
But nothing seems to help.
Same if I create the project as a "Program"...
I have added indylaz as required package and also later LCLbase, but
the errors persist.
Building the program leaves me at the last source line:
end.
with all these apparently GUI-related errors.
What have I done wrong here?
Here is the source code of the program:
program IndyTest;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
Classes, SysUtils, CustApp,
{ you can add units after this }
crt, //to check keypresses
remoteserver, //where the main action happens
indylaz;
type
{ TIndyTest }
TIndyTest = class(TCustomApplication)
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
end;
var
RemoteSrv: TRemoteServer;
ch: char;
{ TIndyTest }
procedure TIndyTest.DoRun;
var
ErrorMsg: String;
begin
// quick check parameters
ErrorMsg:=CheckOptions('h', 'help');
if ErrorMsg<>'' then begin
ShowException(Exception.Create(ErrorMsg));
Terminate;
Exit;
end;
{ add your program here }
RemoteSrv := TRemoteServer.Create; //Uses default port 23500
try
RemoteSrv.ClientPort := 23500; //Set port explicitly
Writeln('Starting remote server on port: ' +
IntToStr(RemoteSrv.ClientPort));
RemoteSrv.StartServer;
Writeln('Server running, hit ESC to exit!');
repeat
ch := ReadKey;
until ch=#27; {Esc}
RemoteSrv.StopServer;
finally
RemoteSrv.Free;
end;
// stop program loop
Terminate;
end;
constructor TIndyTest.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException:=True;
end;
var
Application: TIndyTest;
begin
Application:=TIndyTest.Create(nil);
Application.Title:='Remote server';
Application.Run;
Application.Free;
end.
--
Bo Berglund
Developer in Sweden
More information about the lazarus
mailing list