Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2020-07

Cannot compile console application, why?

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

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

Reply by email

Michael Van Canneyt
to Bo Berglund
Bo Berglund wrote 14 lines
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

Looks like you have some GUI related code somewhere.

Show quoted text 13 lines
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;

I suggest to remove indylaz from the uses clause.
It pulls in some GUI related code, probably some design-time stuff.

Michael.

Reply by email

Bo Berglund
to Michael Van Canneyt
Michael Van Canneyt wrote
I suggest to remove indylaz from the uses clause. It pulls in some GUI related code, probably some design-time stuff.

So I have done this:
- deleted the uses indylaz in the lpr file
- removed the LCLbase from project required packages

Still the same behaviour. LCLbase was not there to begin with, I added it as a wild guess but it did nothing so is now removed.

Next I started removing uses clauses one by one in the remoteserver.pas unit where the indy functionality is located and when I had removed these two it did build!

  //StdCtrls,
  //IdBaseComponent,

QUESTION:
---------
What is the correct way to start a new project that is just a console no GUI type program intended to be run as a systemd service on Linux? There are several types of programs to choose from and I have not understood the difference between:
- Simple Program
- Program
- Console application

Bo Berglund Developer in Sweden

Reply by email

Michael Van Canneyt
to Bo Berglund
Bo Berglund wrote 19 lines
On Mon, 6 Jul 2020 07:20:08 +0200 (CEST), Michael Van Canneyt via lazarus wrote: > I suggest to remove indylaz from the uses clause. > It pulls in some GUI related code, probably some design-time stuff. > So I have done this: - deleted the uses indylaz in the lpr file - removed the LCLbase from project required packages Still the same behaviour. LCLbase was not there to begin with, I added it as a wild guess but it did nothing so is now removed. Next I started removing uses clauses one by one in the remoteserver.pas unit where the indy functionality is located and when I had removed these two it did build! //StdCtrls, //IdBaseComponent,

StdCtrls :-)

That's what I said, you have GUI dependencies in your code...

Show quoted text 9 lines
QUESTION: --------- What is the correct way to start a new project that is just a console no GUI type program intended to be run as a systemd service on Linux? There are several types of programs to choose from and I have not understood the difference between: - Simple Program - Program - Console application

They are exactly the same functionally, they just differ in terms of what start code is generated.

Michael.

Reply by email

Bo Berglund
to Michael Van Canneyt
Michael Van Canneyt wrote
StdCtrls :-) That's what I said, you have GUI dependencies in your code...

The Indy test unit implements a simple TCP server and is based on an example I managed to find on the net.
That example used a form to display data rather than using the command line....
But I also had to remove that Indy unit before the errors went away.

I have now tested that I can run the server on Win10 and connect to it. So I can now move forward.
Thanks!

Bo Berglund Developer in Sweden

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: Looks like you have some GUI related code somewhere. I suggest to remove indylaz from the…
Michael Van Canneyt wrote
I suggest to remove indylaz from the uses clause. It pulls in some GUI related code, probably some design-time stuff.

Yeah, from memory, the non-gui related package is called "indy.lpk"

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Bo Berglund
to Bo Berglund: I have created a test application using Lazarus 2.0.8 and fpc 3.0.4 on Windows 10. The…
Bo Berglund wrote 31 lines
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?

FOLLOW-UP on the problem (for future reference)
-----------------------------------------------
After solving this problem as described earlier in this thread I went on with my Delphi->FreePascal porting of an old project, which also needed a serial port replacement component.
I chose LazSerial (available via Online Package Manager in Lazarus).

Now the same problem as outlined earlier in this thread popped up again! In this case I found a few threads in the Lazarus forum where the problem had a solution:
https://forum.lazarus.freepascal.org/index.php/topic,7143.msg33501.html https://forum.lazarus.freepascal.org/index.php/topic,21998.msg129236.html

In the unit where LazSerial is referenced I added an extra uses item like this:

  {$IFDEF FPC}
    interfaces, //Needed for LazSerial to work in a Console program
    LazSerial,  //The serial component
  {$ELSE} //Delphi

When I now build the project the linker does not trigger any complaints about missing Menu related identifiers and the build succeeds!

Bo Berglund Developer in Sweden

Reply by email