Sign in Join

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

Mailing lists / lazarus / 2010-06

Converting a console app

12 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

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

Mattias Gaertner
to Juha Manninen: I am testing the Delphi converter with a console application. Related to:…
Show quoted text 8 lines
Hi, I am testing the Delphi converter with a console application. Related to: http://www.lazarus.freepascal.org/index.php/topic,9746 The converter adds dependency for LCL automatically. I though console apps could need LCL, too, because there are Windows compat functions in units like LCLIntf.

Yes, but you should set the widgetset to nogui.

Show quoted text 5 lines
However, I get linker errors (copied to the end). When I remove the LCL dependency, the program links and runs OK. Why does it happen? The obvious solution is not to add LCL dependency to console apps. Is it always the correct way?

Always? Of course not.

Show quoted text 11 lines
Juha ---------------------------------------------------- Linking /Extra/SW/LazConvertTests/LeipzigSourcen-2010.03.31/ExtractBeta/ExtractBeta /usr/bin/ld: warning: /Extra/SW/LazConvertTests/LeipzigSourcen-2010.03.31/ExtractBeta/link.res contains output sections; did you forget -T? /Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wsimglist.o: In function `REGISTERCUSTOMIMAGELIST':

You forgot to add the 'interfaces' unit.

Mattias

Reply by email

dmitry boyarintsev
to Juha Manninen: I am testing the Delphi converter with a console application. Related to:…
Juha Manninen wrote
Why does it happen? The obvious solution is not to add LCL dependency to console apps. Is it always the correct way?

It's lack of Interfaces unit.

Console applications are not always Windows dependant. So I guess adding LCL dependency + Interfaces, LCLIntf units should NOT be strict.

i.e.

begin
  writeln('hello world');
end.

No need for LCL units here :)

thanks,
dmitry

Reply by email

Juha Manninen

Hi,

I am testing the Delphi converter with a console application. Related to: http://www.lazarus.freepascal.org/index.php/topic,9746

The converter adds dependency for LCL automatically. I though console apps could need LCL, too, because there are Windows compat functions in units like LCLIntf.
However, I get linker errors (copied to the end).
When I remove the LCL dependency, the program links and runs OK.

Why does it happen? The obvious solution is not to add LCL dependency to console apps. Is it always the correct way?

Juha

----------------------------------------------------

Linking
/Extra/SW/LazConvertTests/LeipzigSourcen-2010.03.31/ExtractBeta/ExtractBeta /usr/bin/ld: warning:
/Extra/SW/LazConvertTests/LeipzigSourcen-2010.03.31/ExtractBeta/link.res contains output sections; did you forget -T?
/Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wsimglist.o: In function `REGISTERCUSTOMIMAGELIST':
/Extra/SW/lazarus_gitsvn/trunk/lcl//widgetset/wsimglist.pp:266: undefined reference to `WSRegisterCustomImageList'
/Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wsmenus.o: In function `REGISTERMENUITEM':
/Extra/SW/lazarus_gitsvn/trunk/lcl//widgetset/wsmenus.pp:204: undefined reference to `WSRegisterMenuItem'
/Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wsmenus.o: In function `REGISTERMENU':
/Extra/SW/lazarus_gitsvn/trunk/lcl//widgetset/wsmenus.pp:215: undefined reference to `WSRegisterMenu'
/Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wsmenus.o: In function `REGISTERMAINMENU':
/Extra/SW/lazarus_gitsvn/trunk/lcl//widgetset/wsmenus.pp:226: undefined reference to `WSRegisterMainMenu'
/Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wsmenus.o: In function `REGISTERPOPUPMENU':
/Extra/SW/lazarus_gitsvn/trunk/lcl//widgetset/wsmenus.pp:237: undefined reference to `WSRegisterPopupMenu'
/Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wscontrols.o: In function `REGISTERDRAGIMAGELIST':
/Extra/SW/lazarus_gitsvn/trunk/lcl//widgetset/wscontrols.pp:355: undefined reference to `WSRegisterDragImageList'
/Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wscontrols.o: In function `REGISTERCONTROL':
/Extra/SW/lazarus_gitsvn/trunk/lcl//widgetset/wscontrols.pp:365: undefined reference to `WSRegisterControl'
/Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wscontrols.o: In function `REGISTERWINCONTROL':
/Extra/SW/lazarus_gitsvn/trunk/lcl//widgetset/wscontrols.pp:375: undefined reference to `WSRegisterWinControl'
/Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wscontrols.o: In function `REGISTERGRAPHICCONTROL':
/Extra/SW/lazarus_gitsvn/trunk/lcl//widgetset/wscontrols.pp:385: undefined reference to `WSRegisterGraphicControl'
/Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wscontrols.o: In function `REGISTERCUSTOMCONTROL':
/Extra/SW/lazarus_gitsvn/trunk/lcl//widgetset/wscontrols.pp:396: undefined reference to `WSRegisterCustomControl'
/Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wsforms.o: In function `REGISTERSCROLLINGWINCONTROL':
/Extra/SW/lazarus_gitsvn/trunk/lcl//widgetset/wsforms.pp:203: undefined reference to `WSRegisterScrollingWinControl'
/Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wsforms.o: In function `REGISTERSCROLLBOX':
/Extra/SW/lazarus_gitsvn/trunk/lcl//widgetset/wsforms.pp:214: undefined reference to `WSRegisterScrollBox'
/Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wsforms.o: In function `REGISTERCUSTOMFRAME':
/Extra/SW/lazarus_gitsvn/trunk/lcl//widgetset/wsforms.pp:225: undefined reference to `WSRegisterCustomFrame'
/Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wsforms.o: In function `REGISTERCUSTOMFORM':
/Extra/SW/lazarus_gitsvn/trunk/lcl//widgetset/wsforms.pp:236: undefined reference to `WSRegisterCustomForm'
/Extra/SW/lazarus_gitsvn/trunk/lcl/units/i386-linux/wsforms.o: In function `REGISTERHINTWINDOW':
/Extra/SW/lazarus_gitsvn/trunk/lcl//widgetset/wsforms.pp:247: undefined reference to `WSRegisterHintWindow'
Error: Error while linking

Reply by email

Juha Manninen
to dmitry boyarintsev: It's lack of Interfaces unit. Console applications are not always Windows dependant. So I…
It's lack of Interfaces unit.

Right! I forgot it because normally it is added by the IDE save project function and not by converter.
The save function adds it only if it finds Forms unit in uses section (IIRC).

Show quoted text 11 lines
Console applications are not always Windows dependant. So I guess adding LCL dependency + Interfaces, LCLIntf units should NOT be strict. i.e. begin writeln('hello world'); end. No need for LCL units here :)

Yes. I just need to decide clear rules for the converter. I don't want to make any deep analysis about if a called function is found in LCL units. (Unless there is an easy way to do it).
I think it is OK to always all LCL dependency and Interfaces unit.

Juha

Reply by email

Michael Van Canneyt
to Juha Manninen
Juha Manninen wrote 23 lines
> It's lack of Interfaces unit. Right! I forgot it because normally it is added by the IDE save project function and not by converter. The save function adds it only if it finds Forms unit in uses section (IIRC). > Console applications are not always Windows dependant. > So I guess adding LCL dependency + Interfaces, LCLIntf units should > NOT be strict. > > i.e. > > begin > writeln('hello world'); > end. > > No need for LCL units here :) Yes. I just need to decide clear rules for the converter. I don't want to make any deep analysis about if a called function is found in LCL units. (Unless there is an easy way to do it). I think it is OK to always all LCL dependency and Interfaces unit.

I think it is definitely NOT OK to do so.

There is no reason whatsoever to drag in the nogui widgetset and whatnot in a console application. That is just plain wrong. Someone using e.g. the forms unit in a console application is coding wrong, and he should be pointed out this fact by letting the compile step fail.

Michael.

Reply by email

Mattias Gaertner
to Juha Manninen: Using the Forms unit would be wrong, sure, but there are Windows compatibility functions…
Show quoted text 12 lines
> There is no reason whatsoever to drag in the nogui widgetset and whatnot in > a console application. That is just plain wrong. Someone using e.g. the > forms unit in a console application is coding wrong, and he should be > pointed out this fact by letting the compile step fail. Using the Forms unit would be wrong, sure, but there are Windows compatibility functions in eg. LCLIntf which are not only for GUI. LCLIntf is part of LCL. NoGUI widgetset is light compared to the "real" widgetsets and it should be no problem. Am I right?

It is light, but it still has much more fat than just using a few LCL units (e.g. FileUtils). IMO the nogui widgetset is only needed for a few rare cases.
Maybe you can do a simple word search for some of the nogui widgetset functions. If they are not used, do not add it.
Or: make it an option.

Mattias

Reply by email

Michael Van Canneyt
to Juha Manninen: Using the Forms unit would be wrong, sure, but there are Windows compatibility functions…
Juha Manninen wrote 7 lines
> There is no reason whatsoever to drag in the nogui widgetset and whatnot in > a console application. That is just plain wrong. Someone using e.g. the > forms unit in a console application is coding wrong, and he should be > pointed out this fact by letting the compile step fail. Using the Forms unit would be wrong, sure, but there are Windows compatibility functions in eg. LCLIntf which are not only for GUI. LCLIntf is part of LCL.

In that case, these functions should be separated out in a unit that does not use anything else (read: gui stuff) from the LCL.

NoGUI widgetset is light compared to the "real" widgetsets and it should be no problem.

It is a problem, since you drag in a lot of stuff that should not be there in the first place.

People using windows functions in a console application should be taught to use proper system-independent code provided by FPC. You should not enourage a bad writing style. In the case the point is to just compile a windows application using FPC, you might as well leave the windows unit in the uses clause and be done with it.

Am I right?

IMHO: Definitely not. You hide what is in my opinion a programming error: using a Windows API in so-called portable code. On top of that, you drag in totally unneeded code which serves in essence only to make the linker happy. I'm surprised anyone thought of the nogui widget set to start with ! :/

Michael.

Reply by email

Juha Manninen
to Michael Van Canneyt: I think it is definitely NOT OK to do so. There is no reason whatsoever to drag in the…
There is no reason whatsoever to drag in the nogui widgetset and whatnot in a console application. That is just plain wrong. Someone using e.g. the forms unit in a console application is coding wrong, and he should be pointed out this fact by letting the compile step fail.

Using the Forms unit would be wrong, sure, but there are Windows compatibility functions in eg. LCLIntf which are not only for GUI. LCLIntf is part of LCL.

NoGUI widgetset is light compared to the "real" widgetsets and it should be no problem.

Am I right?

Juha

Reply by email

Vincent Snijders
to Juha Manninen

2010/6/30 Juha Manninen :

Show quoted text 8 lines
> There is no reason whatsoever to drag in the nogui widgetset and whatnot in > a ?console application. That is just plain wrong. Someone using e.g. the > forms unit in a console application is coding wrong, and he should be > pointed out this fact by letting the compile step fail. Using the Forms unit would be wrong, sure, but there are Windows compatibility functions in eg. LCLIntf which are not only for GUI. LCLIntf is part of LCL.

What LCLIntf functions do you want to use? I guess there should be better cross platform options in the RTL and FCL.

Vincent

Reply by email

Juha Manninen
to Vincent Snijders

Hi

What LCLIntf functions do you want to use? I guess there should be better cross platform options in the RTL and FCL.

I don't even want to make console applications myself, the question is about converting existing Delphi applications.

Now I implemented it like you and Michael wanted. So, neither LCL dependency nor LCLIntf unit are added. I guess most console apps can do without LCL, the problems are more caused by windows funcs and types which can't be converted easily.

I can later add an option to include LCL and NoGUI widgetset for the rare cases when it is needed. That is what Mattias suggested.

Juha

Reply by email