uses myunit in '../src/myunit.pas' ?

classic Classic list List threaded Threaded
46 messages Options
123
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

uses myunit in '../src/myunit.pas' ?

fredvs
Hello.

There is myprogram.pas in /home/me/myproject/example.

This program uses myunit.pas from /home/me/myproject/src.

myunit.pas uses myunit2.pas and myunit3.pas that are also in home/me/myproject/src.

Using this:

program myprogram;
...
uses myunit in '../src/myunit.pas';

load indeed /home/me/myproject/src/myunit.pas but there are error messages because myunit.pas does not find the units that are in uses section.

Here myunit.pas:

unit myunit;
...
uses myunit2, myunit3;
...

How to do ?

Thanks.

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

timveldhuizen
Unit names are considered to be unique, so strictly, for the compiler
there is no need to specify the path explicitly in code when the unit
path is given to the compiler when calling it from the command line.

To do this, use the -Fu parameter when calling fpc to include ../src to
the unit path.

Greetings,
Tim Veldhuizen.

On 11/02/17 04:07, fredvs wrote:

> Hello.
>
> There is myprogram.pas in /home/me/myproject/example.
>
> This program uses myunit.pas from /home/me/myproject/src.
>
> myunit.pas uses myunit2.pas and myunit3.pas that are also in
> home/me/myproject/src.
>
> Using this:
>
> program myprogram;
> ...
> uses myunit in '../src/myunit.pas';
>
> load indeed /home/me/myproject/src/myunit.pas but there are error messages
> because myunit.pas does not find the units that are in uses section.
>
> Here myunit.pas:
>
> unit myunit;
> ...
> uses myunit2, myunit3;
> ...
>
> How to do ?
>
> Thanks.
>
> Fre;D
>
>
>
>
> -----
> Many thanks ;-)
> --
> View this message in context: http://free-pascal-general.1045716.n5.nabble.com/uses-myunit-in-src-myunit-pas-tp5727626.html
> Sent from the Free Pascal - General mailing list archive at Nabble.com.
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

fredvs

Hello Tim.


OK, many thanks for your light.


Fre;D


De : [hidden email] <[hidden email]> de la part de Tim Veldhuizen <[hidden email]>
Envoyé : samedi 11 février 2017 06:04
À : [hidden email]
Objet : Re: [fpc-pascal] uses myunit in '../src/myunit.pas' ?
 
Unit names are considered to be unique, so strictly, for the compiler
there is no need to specify the path explicitly in code when the unit
path is given to the compiler when calling it from the command line.

To do this, use the -Fu parameter when calling fpc to include ../src to
the unit path.

Greetings,
Tim Veldhuizen.

On 11/02/17 04:07, fredvs wrote:
> Hello.
>
> There is myprogram.pas in /home/me/myproject/example.
>
> This program uses myunit.pas from /home/me/myproject/src.
>
> myunit.pas uses myunit2.pas and myunit3.pas that are also in
> home/me/myproject/src.
>
> Using this:
>
> program myprogram;
> ...
> uses myunit in '../src/myunit.pas';
>
> load indeed /home/me/myproject/src/myunit.pas but there are error messages
> because myunit.pas does not find the units that are in uses section.
>
> Here myunit.pas:
>
> unit myunit;
> ...
> uses myunit2, myunit3;
> ...
>
> How to do ?
>
> Thanks.
>
> Fre;D
>
>
>
>
> -----
> Many thanks ;-)
> --
> View this message in context: http://free-pascal-general.1045716.n5.nabble.com/uses-myunit-in-src-myunit-pas-tp5727626.html
free-pascal-general.1045716.n5.nabble.com
uses myunit in '../src/myunit.pas' ?. Hello. There is myprogram.pas in /home/me/myproject/example. This program uses myunit.pas from /home/me/myproject/src. myunit.pas uses myunit2.pas and...


> Sent from the Free Pascal - General mailing list archive at Nabble.com.
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
lists.freepascal.org
NOTE ***** Due to incidents with spambots subscribing to the list and spamming it, your first message(s) may be delayed a bit before ...



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
lists.freepascal.org
NOTE ***** Due to incidents with spambots subscribing to the list and spamming it, your first message(s) may be delayed a bit before ...



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

noreply
On Sat, February 11, 2017 5:56 am, Fred van Stappen wrote:

>
> Unit names are considered to be unique, so strictly, for the compiler
> there is no need to specify the path explicitly in code when the unit path
> is given to the compiler when calling it from the command line.
>
> To do this, use the -Fu parameter when calling fpc to include ../src to
> the unit path.
>
> Greetings,
> Tim Veldhuizen.
>
>

I have found some use cases for hard coded paths in the source files..
although these use cases are rare. I think even delphi main project DPR
file does this, if I remember correctly, but I found other uses cases
other than that.  One example might be when you are writing a quick
program and don't want to send in a whole bunch of -Fu options and go into
dialog boxes in lazarus configuring it, so you just quickly write it in
your program ../someunit instead of configuring -Fu which can be obnoxious
and tedious.. But that's just one use case. Another use case, AFAIR was a
build system instead of gnu make.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

timveldhuizen
Indeed, I can confirm Delphi does this. I think since 2009 or XE or so,
but AFAIK it doesn't need to. It does it only for the files that are
explicitly added to the project, but those are also in the dproj file.
And it would compile just fine without explicitly referring to the files
in the dpr file, so I'm not exactly sure why it does it. Perhaps it's a
kind of optimization for the caching system in the IDE..

For units that contain a form, there is also the name (value of the name
property, not the classname if I recall correctly) of the form in curly
braces comment behind the file reference and it seems the IDE does
something with that as well. I can't remember clearly, but I recall an
odd anomaly in a big application with lots of legacy that had something
to do with such a comment for a unit with a form.


On 12/02/17 15:07, Lars wrote:

> On Sat, February 11, 2017 5:56 am, Fred van Stappen wrote:
>> Unit names are considered to be unique, so strictly, for the compiler
>> there is no need to specify the path explicitly in code when the unit path
>> is given to the compiler when calling it from the command line.
>>
>> To do this, use the -Fu parameter when calling fpc to include ../src to
>> the unit path.
>>
>> Greetings,
>> Tim Veldhuizen.
>>
>>
> I have found some use cases for hard coded paths in the source files..
> although these use cases are rare. I think even delphi main project DPR
> file does this, if I remember correctly, but I found other uses cases
> other than that.  One example might be when you are writing a quick
> program and don't want to send in a whole bunch of -Fu options and go into
> dialog boxes in lazarus configuring it, so you just quickly write it in
> your program ../someunit instead of configuring -Fu which can be obnoxious
> and tedious.. But that's just one use case. Another use case, AFAIR was a
> build system instead of gnu make.
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

noreply
On 2017-02-12 01:33, Tim Veldhuizen wrote:
> Indeed, I can confirm Delphi does this. I think since 2009 or XE or
> so,

I'm too lazy to check right now, but I think even delphi 5 and such used
paths in the dpr (project) file

Would be interesting to find out the real reason, but once again, I'm
too lazy to head down that path and post a question on stackoverflow
(plus, they would likely shut it down as off topic or irrelavent,
knowing those turds)
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

Mattias Gaertner
In reply to this post by timveldhuizen
On Sun, 12 Feb 2017 15:33:23 +0800
Tim Veldhuizen <[hidden email]> wrote:

> Indeed, I can confirm Delphi does this. I think since 2009 or XE or so,
> but AFAIK it doesn't need to. It does it only for the files that are
> explicitly added to the project, but those are also in the dproj file.
> And it would compile just fine without explicitly referring to the files
> in the dpr file, so I'm not exactly sure why it does it. Perhaps it's a
> kind of optimization for the caching system in the IDE..

Delphi uses them just a marker for the IDE, that the units belongs
to the project. It does not create different code.
It uses that system since at least Delphi 3.

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

Marco van de Voort
In reply to this post by noreply
In our previous episode, Lars said:
> I have found some use cases for hard coded paths in the source files..
> although these use cases are rare. I think even delphi main project DPR
> file does this, if I remember correctly, but I found other uses cases
> other than that.

I think that is the main reason, but that was for the IDE/designers benefit,
not the compiler's. Just like the form names are mentioned in comments in
the .dpr.

Later the syntax was recycled to tackle file case problems on Kylix.

But the problem is what are relative paths relative too? Project file? The
actual source file?

>  One example might be when you are writing a quick program and don't want
> to send in a whole bunch of -Fu options and go into dialog boxes in
> lazarus configuring it, so you just quickly write it in your program
> ../someunit instead of configuring -Fu which can be obnoxious and
> tedious..  But that's just one use case.  Another use case, AFAIR was a
> build system instead of gnu make.

IMHO these are all shaky uses cases, and actually doing it right is quite
hard.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

Mattias Gaertner
On Sun, 12 Feb 2017 16:17:01 +0100 (CET)
[hidden email] (Marco van de Voort) wrote:

>[...]
> >  One example might be when you are writing a quick program and don't want
> > to send in a whole bunch of -Fu options and go into dialog boxes in
> > lazarus configuring it, so you just quickly write it in your program
> > ../someunit instead of configuring -Fu which can be obnoxious and
> > tedious..  But that's just one use case.  Another use case, AFAIR was a
> > build system instead of gnu make.  
>
> IMHO these are all shaky uses cases, and actually doing it right is quite
> hard.

Why is using -Fu hard?

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

Marco van de Voort
In our previous episode, Mattias Gaertner said:
> > > ../someunit instead of configuring -Fu which can be obnoxious and
> > > tedious..  But that's just one use case.  Another use case, AFAIR was a
> > > build system instead of gnu make.  
> >
> > IMHO these are all shaky uses cases, and actually doing it right is quite
> > hard.
>
> Why is using -Fu hard?

It requires a project file and Delphi is somewhat shaky with relative paths
which makes configuring it hard. One has the choice between abs paths, the
subset trick, or doubtful relative paths.

(Delphi evaluates relative paths relative to the current directory, which
can be random unless you load it via file->open project)
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

fredvs
> Why is using -Fu hard?

Yes, of course it could be a solution but I would prefer something inside the code.

By the way, IMO, and it  is valable for lot of languages, the way to define/use the path (of units or libraries or dependencies) is very archaic. Only LD_LIBRARY_PATH for libraries and for units I do not know if it exist.

For example, fpc can load dynamically libraries but it is not usable if that libraries depend on other libraries.

It would be great (IMO) if fpc provide, unlike other compilers, some more modern ways to use  things (units, libraries, etc...) with the appropriate need-path.

But, once again, it is only a IMO.

Thanks.

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

Sven Barth-2
On 12.02.2017 19:25, fredvs wrote:
> For example, fpc can load dynamically libraries but it is not usable if that
> libraries depend on other libraries.
>
> It would be great (IMO) if fpc provide, unlike other compilers, some more
> modern ways to use  things (units, libraries, etc...) with the appropriate
> need-path.
>
> But, once again, it is only a IMO.

Loading libraries is handled by the OS, not by the compiler or the RTL
and every OS has its own way to deal with dependencies.

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

fredvs
> Loading libraries is handled by the OS, not by the compiler or the RTL
> and every OS has its own way to deal with dependencies.

Yes but the compiler could give some command to the os too...

Of course every OS has its own way to deal with dependencies but that is the power of fpc, he knows how to speak with those different os.

For example, TProcess also is very os dependent and it uses "environnement" parameter (that is also very os dependent).

OK for libraries, (even that I think that the compiler could help), but for units, what about create something that could define path of units used in use section...

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

Michael Van Canneyt


On Sun, 12 Feb 2017, fredvs wrote:

>> Loading libraries is handled by the OS, not by the compiler or the RTL
>> and every OS has its own way to deal with dependencies.
>
> Yes but the compiler could give some command to the os too...
>
> Of course every OS has its own way to deal with dependencies but that is the
> power of fpc, he knows how to speak with those different os.
>
> For example, TProcess also is very os dependent and it uses "environnement"
> parameter (that is also very os dependent).

No it is not. Every OS has an environment ?

> OK for libraries, (even that I think that the compiler could help), but for
> units, what about create something that could define path of units used in
> use section...

You already have such a thing: Lazarus and it's packages.
In FPC, you can use fpmake and fppkg.

But thinking that the compiler itself will automagically determine the path:
that's simply not realistic.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

fredvs
> But thinking that the compiler itself will automagically determine the path: that's simply not realistic.

Really ?

When the compiler reads uses section and find a "in" like here :

uses myunit in '/thepath/src/myunit.pas';

He could do something like:
...
if fpcword = 'in' then begin
IncludeSearchPath((ExtractFilePath('/thepath/src/myunit.pas');
IncludeUnit('/thepath/src/myunit.pas');
...

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

fredvs
In reply to this post by Michael Van Canneyt
>> For example, TProcess also is very os dependent and it uses "environnement"
>> parameter (that is also very os dependent).

> No it is not. Every OS has an environment ?

So it is exactly what I propose:

a TLoadLibrary with some features adapted for libraries that TProcess uses for executables (like environnement).
Of course TLoadLibrary will have a LoadLibrary() and SafeLoadLibrary() but some properties too.

What do you think ?

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

Michael Van Canneyt


On Sun, 12 Feb 2017, fredvs wrote:

>>> For example, TProcess also is very os dependent and it uses
> "environnement"
>>> parameter (that is also very os dependent).
>
>> No it is not. Every OS has an environment ?
>
> So it is exactly what I propose:
>
> a TLoadLibrary with some features adapted for libraries that TProcess uses
> for executables (like environnement).
> Of course TLoadLibrary will have a LoadLibrary() and SafeLoadLibrary() but
> some properties too.
>
> What do you think ?

I don't see the point at all.
Why would you copy functionality that the OS provides out of the box ?

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

Graeme Geldenhuys-6
In reply to this post by fredvs
On 2017-02-12 18:25, fredvs wrote:
> Yes, of course it could be a solution but I would prefer something inside
> the code.

AggPas (also included with fpGUI) has a build system where relative
paths can be defined as code comments in the top of the program unit.
Relative paths are relative to the program unit. The build system then
finds that info and builds the correct FPC (or Delphi) command line
parameters to build the project. AggPas uses this system for all the 20+
demos it includes.

Fred, you are welcome to take a look at that too. AggPas inside fpGUI is
located at <fpgui>/src/corelib/render/software/agg-demos/

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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

fredvs
Hello Graeme.

OK, thanks, I will take a look.

@Michael:

>I don't see the point at all.

I will show you later TLoadlibrary(), maybe you will see better then.

Huh, and what about: ?

>> But thinking that the compiler itself will automagically determine the path: that's simply not realistic.

> Really ?

> When the compiler reads uses section and find a "in" like here :

> uses myunit in '/thepath/src/myunit.pas';

> He could do something like:
> ...
> if fpcword = 'in' then begin
> IncludeSearchPath((ExtractFilePath('/thepath/src/myunit.pas'); // this added
>...
> IncludeUnit('/thepath/src/myunit.pas');
> ...

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: uses myunit in '../src/myunit.pas' ?

Michael Van Canneyt


>>> But thinking that the compiler itself will automagically determine the
>>> path: that's simply not realistic.
>
>> Really ?
>
>> When the compiler reads uses section and find a "in" like here :
>
>> uses myunit in '/thepath/src/myunit.pas';
>
>> He could do something like:
>> ...
>> if fpcword = 'in' then begin
>> IncludeSearchPath((ExtractFilePath('/thepath/src/myunit.pas'); // this
>> added
>> ...
>> IncludeUnit('/thepath/src/myunit.pas');

The compiler already does this.

-----------------------------------
cadwal: >cat p.pp
program p;

uses unita in 'Documents/unita.pp';

begin
end.

cadwal: >cat Documents/unita.pp
unit unita;

interface

implementation

end.

cadwal: >fpc p.pp
cadwal: >
-----------------------------------

But honestly: you're much better off using fpmake or lazarus packages.

The 'in' construct was/is a serious contender for "the worst idea ever" of Borland.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
123
Loading...