Sign in Join

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

Mailing lists / lazarus / 2008-07

When adding a packages it adds to uses clause

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi,

Why when I add one of my own custom packages, it adds the package's main unit to the projects uses clause? eg: I have a packages called fpgui_package.lpk and when I add it as a requirement to a project, the uses clause contains 'fpgui_package' as one of the units. If I manually delete it, it still compiles without problems, so why add it in the first place?

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Hess, Philip J
to Graeme Geldenhuys

Graeme,

The IDE has always done that with packages. I believe I reported this a couple years ago but didn't look into what it would take to suppress this behavior.

Here's what I put in the Orpheus port notes about that:

"When you first add an Orpheus control to a form, Lazarus will add the Orpheus unit to the uses section of your main source file (.lpr). This pulls in a great deal of code that you don't need. Delete the Orpheus unit from the uses section to reduce the size of your executable file."

Since the package's main unit references all registered units, this can be a huge amount of code pulled in on platforms that don't have a smart linker (OS X for one).

Thanks.

-Phil

Earlier message 24 lines
-----Original Message----- From: [mailto:] On Behalf Of Graeme Geldenhuys Sent: Monday, July 07, 2008 1:37 PM To: General mailing list Subject: [Lazarus] When adding a packages it adds to uses clause Hi, Why when I add one of my own custom packages, it adds the package's main unit to the projects uses clause? eg: I have a packages called fpgui_package.lpk and when I add it as a requirement to a project, the uses clause contains 'fpgui_package' as one of the units. If I manually delete it, it still compiles without problems, so why add it in the first place? Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Vincent Snijders
to Graeme Geldenhuys: Why when I add one of my own custom packages, it adds the package's main unit to the…
Graeme Geldenhuys wrote
uses clause contains 'fpgui_package' as one of the units. If I manually delete it, it still compiles without problems, so why add it in the first place?

To support package, which only do registration, like for example the jpeg reader (not used atm). It registers its reader in the intialization section of one the units in the package, but is not used anywhere in the application further on.

Vincent

Reply by email

Graeme Geldenhuys
to Hess, Philip J: The IDE has always done that with packages. I believe I reported this a couple years ago…

2008/7/7 Hess, Philip J :

The IDE has always done that with packages. I believe I reported this a couple years ago but didn't look into what it would take to suppress this behavior.

I have noticed this a year or so ago as well, but never reported it. Now it bugs me again. :)

Since the package's main unit references all registered units, this can be a huge amount of code pulled in on platforms that don't have a smart linker (OS X for one).

Exactly, and if you don't use Lazarus to compile the program (eg: via command line), this could cause problems as well I think. If the package (*.lpk) file is not located in the normal source code directories, the compiler will not find the package unit.

Can we please remove that unit from the uses clause? Lazarus I believe is intelligent enough to know the required package from the .lps or .lpi files and where it is located.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Vincent Snijders: To support package, which only do registration, like for example the jpeg reader (not…

2008/7/7 Vincent Snijders :

To support package, which only do registration, like for example the jpeg reader (not used atm). It registers its reader in the intialization section of one the units in the package, but is not used anywhere in the application further on.

Surely there must be a smarter way for Lazarus to know when to include or not include the package unit into a project. I just tested Philip Hess's theory and he is 100% correct.

I compiled a simply application using fpgui_toolkit.lpk package (no smart linking) and with 'fpgui_package' in uses clause. A 4.3Mb executable was created. I enabled smart linking and the file shrunk to 3.5Mb. I then removed the 'fpgui_package' reference in the uses clause and it shrunk further to 2.8Mb. That's a HUGE difference compared to the previous tries.

Oh, and I ran 'strip' on each executable. The first 4.3Mb file went down to 2.9Mb. The last 2.8Mb file went down to 590Kb.

As far as I know, a Lazarus Package contains a flag or something to say it's got a Register() function. In that case include the package unit in the uses clause. If the packages doesn't contain a Register() function, exclude it from the uses clause!

When deploying apps over the internet every byte counts! No need to follow Microsoft's idea of creating every application with bucket loads of bloat.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Mattias Gaertner
to Graeme Geldenhuys: 2008/7/7 Vincent Snijders : Surely there must be a smarter way for Lazarus to know when…
Show quoted text 9 lines
2008/7/7 Vincent Snijders : > To support package, which only do registration, like for example the > jpeg reader (not used atm). It registers its reader in the > intialization section of one the units in the package, but is not > used anywhere in the application further on. Surely there must be a smarter way for Lazarus to know when to include or not include the package unit into a project. I just tested Philip Hess's theory and he is 100% correct.

The IDE adds the package to the uses section of the program *once* and only for the convenience of the programmer. If he don't like it, he can remove it. Just like any unit or CreateForm statement, that the IDE adds too.

Show quoted text 5 lines
[...] As far as I know, a Lazarus Package contains a flag or something to say it's got a Register() function. In that case include the package unit in the uses clause. If the packages doesn't contain a Register() function, exclude it from the uses clause!

The Register procedures are not called by this.
As Vincents already said:
It's added to call the initialization sections.

When deploying apps over the internet every byte counts! No need to follow Microsoft's idea of creating every application with bucket loads of bloat.

Then decide what initializations you needs and remove the unneeded. But keep in mind, if the package changes, you have to add/remove/rename units yourself.

And with dynamic libraries you have to add the package anyway (When eventually FPC supports them).

Mattias

Reply by email

Graeme Geldenhuys
to Mattias Gaertner

2008/7/8 Mattias Gaertner :

Show quoted text 5 lines
The IDE adds the package to the uses section of the program *once* and only for the convenience of the programmer. If he don't like it, he can remove it. Just like any unit or CreateForm statement, that the IDE adds too.

A convenience for the programmer, at an expence of a much larger executable. And yes, I do remove the unit, but sometimes I forget. One good thing like you said, it only happens once, when the packages was added to the project.

The Register procedures are not called by this. As Vincents already said: It's added to call the initialization sections.

My mistake, I got confused between initialization section and the Register() funcion (used for registering with the IDE).

Show quoted text 7 lines
> When deploying apps over the internet every byte counts! No need to > follow Microsoft's idea of creating every application with bucket > loads of bloat. Then decide what initializations you needs and remove the unneeded. But keep in mind, if the package changes, you have to add/remove/rename units yourself.

Sorry, I lost you on the last statement. Could you explain. I use a package called fpgui_toolkit.lpk. I can add, remove or change units, and it doesn't affect the projects using that packages. I simply need to recompile those projects.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Mattias Gaertner
to Graeme Geldenhuys
Show quoted text 10 lines
2008/7/8 Mattias Gaertner : [...] > Then decide what initializations you needs and remove the unneeded. > But keep in mind, if the package changes, you have to > add/remove/rename units yourself. Sorry, I lost you on the last statement. Could you explain. I use a package called fpgui_toolkit.lpk. I can add, remove or change units, and it doesn't affect the projects using that packages. I simply need to recompile those projects.

I meant, iff you remove the package, you have to add the needed units yourself, to make sure that all initialization sections are called.

Mattias

Reply by email