Additional include directories
Additional include directories
Hello!
Reusable code is great, but can be tedious when wanting to use the same reusable code across multiple projects, especially if changing something in that code library and needing the change to be available to all projects.
Of course there is using compiler constants like the PB home directory, and one could always use git submodules too, but could we possibly look to having the option to specify additional include directories in the compiler options (being able to resolve env vars would be a huge benefit)? that way we're not limited to using PB home directory, or even worse, hard-coded directories in-code that fall outside of the project's scope.
In terms of how it would work, upon an include/xinclude, if the file doesn't exist relative to the project/file directory, then the compiler could go through the list of additional included directories to find the file before declaring it missing.
Thanks!
Reusable code is great, but can be tedious when wanting to use the same reusable code across multiple projects, especially if changing something in that code library and needing the change to be available to all projects.
Of course there is using compiler constants like the PB home directory, and one could always use git submodules too, but could we possibly look to having the option to specify additional include directories in the compiler options (being able to resolve env vars would be a huge benefit)? that way we're not limited to using PB home directory, or even worse, hard-coded directories in-code that fall outside of the project's scope.
In terms of how it would work, upon an include/xinclude, if the file doesn't exist relative to the project/file directory, then the compiler could go through the list of additional included directories to find the file before declaring it missing.
Thanks!
Last edited by akamicah on Thu May 12, 2022 11:59 am, edited 1 time in total.
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Additional include directories
I don't think that's a good idea, because then it remains nebulous which files were actually compiled in the end.akamicah wrote:In terms of how it would work, upon an include/xinclude, if the file doesn't exist relative to the project/file directory, then the compiler could go through the list of additional included directories to find the file before declaring it missing.
With "XIncludeFile" you can include arbitrary source code files and the effect of this command is self-documenting.
You can even use "IncludePath" if you want.
Re: Additional include directories
I don't think it'd be as much of an issue as you might think. Being able to reference external directories of reusable code is very common across compilers of other languages, and as for nebulously, providing the developer uses it wisely then there should be no issue.Little John wrote: Wed May 11, 2022 3:47 pmI don't think that's a good idea, because then it remains nebulous which files were actually compiled in the end.akamicah wrote:In terms of how it would work, upon an include/xinclude, if the file doesn't exist relative to the project/file directory, then the compiler could go through the list of additional included directories to find the file before declaring it missing.
With "XIncludeFile" you can include arbitrary source code files and the effect of this command is self-documenting.
You can even use "IncludePath" if you want.
An example could be a directory of reusable code where each module/library is in it's own subdirectory (a method adopted by a lot of frameworks)
Additional include directory:
.../myIncludes
.../myIncludes/maths/vector.pbi
.../myIncludes/crypt/rc4.pbi
If the project referenced ".../myIncludes" then the file to be included would be "maths/vector.pbi" or "crypt/rc4.pbi"
You could also create custom constants in the compiler option to point to a directory, but it would certainly be cleaner to separate the concerns IMO
Re: Additional include directories
What's wrong with using "IncludePath" in your code to point to an external folder of files? It does what you want.
Re: Additional include directories
Hard-coded paths in code that fall outside the project's folder/scope is a very ugly and bad practice, especially if you distribute your code.BarryG wrote: Thu May 12, 2022 11:08 am What's wrong with using "IncludePath" in your code to point to an external folder of files? It does what you want.
Say your project is in /home/micah/Projects/myProject and a library of shared code is in /home/micah/Projects/myBigCodebase if you IncludePath to "../myBigCodebase" then it's outside of your project's scope, and the second you move your project, or the second you bring it to another machine where the paths are different, it breaks
- StarBootics
- Addict
- Posts: 1006
- Joined: Sun Jul 07, 2013 11:35 am
- Location: Canada
Re: Additional include directories
From my perspective NO! When you use IncludePath the problem is if you rearrange your folder you have to change the path pointed out in the IncludePath.BarryG wrote: Thu May 12, 2022 11:08 am What's wrong with using "IncludePath" in your code to point to an external folder of files? It does what you want.
That's why I'm using ToolBoxManager You still need to specify the file you want but the path to it is not required at all. The drawback : work only with the Main file.
Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
Re: Additional include directories
The problem with
is, that it is different for every installation of PureBasic (current/old/beta version).
If we could set additional include search paths inside the IDE or specify locations
at the command line (-I "the/path/to/my/includes"), it could be really helpful for
specifying the personal folder where includes/libs are to be found.
Code: Select all
IncludePath #PB_Compiler_Home + "includes/"
If we could set additional include search paths inside the IDE or specify locations
at the command line (-I "the/path/to/my/includes"), it could be really helpful for
specifying the personal folder where includes/libs are to be found.
Code: Select all
Macro Includes(file="")
#HomeDir + "purebasic/includes/"+file
EndMacro
IncludePath Includes()
XIncludeFile Includes("my_lib_001.pbi")
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Additional include directories
Any paths that fall outside the project's scope are very ugly in my opinion, regardless whether they are hard-coded or "soft-coded" by means of environment variables or something similar, especially if you distribute your code – because you do not distribute your environment variables together with your code.akamicah wrote:Hard-coded paths in code that fall outside the project's folder/scope is a very ugly and bad practice, especially if you distribute your code.
Programming code should be as self documenting as possible, anything else is bad practice.
So just use "XIncludeFile" with paths inside your project's scope.
Re: Additional include directories
This means you have to copy a library/.pbi you downloaded from the forum or githubLittle John wrote: Thu May 12, 2022 3:30 pm So just use "XIncludeFile" with paths inside your project's scope.
into every project, and on updates you have to replace it inside all projects!?
Of course we can do "XIncludeFile '/users/danilo/git/purebasic/the_lib.pbi'", but when
I share this project with a friend, he can't run/execute it.
That's where specifying a lib/include directory may make sense.
An alternative would be a package manager (https://lib.rs/ or https://pub.dev/) for libs/includes.
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Additional include directories
Exactly.Danilo wrote: Thu May 12, 2022 3:39 pmThis means you have to copy a library/.pbi you downloaded from the forum or githubLittle John wrote: Thu May 12, 2022 3:30 pm So just use "XIncludeFile" with paths inside your project's scope.
into every project, and on updates you have to replace it inside all projects!?
That's not elegant, and I don't like it myself. However, I don't know a solution that is better (from my point of view).
Re: Additional include directories
The solution could be this feature request: Specify additional Include DirectoriesLittle John wrote: Thu May 12, 2022 4:03 pm I don't know a solution that is better (from my point of view).
at command-line or from within the IDE.

-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Additional include directories
Not in my opinion, as I wrote above.Danilo wrote:The solution could be this feature request: Specify additional Include Directories
at command-line or from within the IDE.![]()
Re: Additional include directories
Okay.Little John wrote: Thu May 12, 2022 4:22 pmNot in my opinion, as I wrote above.Danilo wrote:The solution could be this feature request: Specify additional Include Directories
at command-line or from within the IDE.![]()
Re: Additional include directories
IIRC you can define constants at the compilation commandline and in the IDE ..and then use them in include statements?Danilo wrote: Thu May 12, 2022 4:09 pm The solution could be this feature request: Specify additional Include Directories
at command-line or from within the IDE.![]()