Page 1 of 1

Relative Search Path

Posted: Fri May 23, 2025 1:08 am
by gray
With v10 we can use relative search path names:
Relative path names ( ..\..\Lib\General for example) can be used in the search paths. The paths are evaluated before compilation / linking starts and are relative to the folder which contains the initial source file.
Test set-up:

Code: Select all

C:\Astrobe\Test3
  + P1.mod
  + lib0
    + Main.mod
    + M0.mod
  + lib1
    + M1.mod

Code: Select all

MODULE P1;
  IMPORT M0, M1;
END P1.

MODULE Main;
END Main.

MODULE M0;
  IMPORT M1;
END M0.

MODULE M1;
END M1.
Search path:

Code: Select all

lib0
lib1
Building P.mod:

Code: Select all

Astrobe for RP2350 Builder v10.0.1
Builder Phase 1: Checking P.mod and imported modules...

Checking Module Main
  Imports:
  Folder: C:\Astrobe\Test3\lib0
  Status: Missing Main.arm file
Checking Module M1
  Imports:
  Folder: C:\Astrobe\Test3\lib1
  Status: Missing M1.arm file
Checking Module M0
  Imports:
    M1
  Folder: C:\Astrobe\Test3\lib0
  Status: Missing M0.arm file
Checking Module P
  Imports:
    Main
    M0
    M1
  Folder: C:\Astrobe\Test3
  Status: Missing P.arm file
------------------

Builder Phase 2: Compiling missing / outdated modules...

  compiling Main
new symbol file;  code generated = 8 bytes, data = 0 bytes, entries = 0, lines = 2, msecs = 2
------------------
  compiling M1
new symbol file;  code generated = 8 bytes, data = 0 bytes, entries = 0, lines = 5, msecs = 2
------------------
  compiling M0

  Line  Col
     2   13 Error: import not available
The output of Phase 1 shows that the all modules are found, ie. that the relative directory names are resolved correctly into absolute paths, relative to P1.mod. M1.mod gets compiled, but is not found for M0.mod.

With

Code: Select all

lib0
lib1
../lib1
the build works, but that should not be necessary, since we have absolute path names during compilation and linking.

However, if I build with the above search path to get a successful compilation, then delete '../lib1', the linker works successfully, ie. finds all compiled modules with the original search path. It's only part of the compilation that fails.

I have also tried

Code: Select all

./lib0
./lib1
to no avail.

Some more contorted "explorative" definitions:

Does not work:

Code: Select all

lib0
lib1
../Test3/lib1
This works:

Code: Select all

lib0
lib1
../../Test3/lib1
What do I miss? Thanks.

Re: Relative Search Path

Posted: Fri May 23, 2025 4:57 am
by cfbsoftware
A build results in zero or more separate compilations, each with their own, possibly different, set of relative search paths. If all of the compilations succeed, it is followed followed by a link with its own set of relative search paths.

During the compilation phase, relative paths are relative to the folder which contains the module being compiled.

During the linking phase, relative paths are relative to the folder which contains the module (which imports Main) being linked.

Re: Relative Search Path

Posted: Sun Jun 01, 2025 11:14 am
by gray
cfbsoftware wrote:
Fri May 23, 2025 4:57 am
During the compilation phase, relative paths are relative to the folder which contains the module being compiled.

During the linking phase, relative paths are relative to the folder which contains the module (which imports Main) being linked.
Thinking this through, it follows that we can have a set of relative directory paths that allow sucessful compilation, but not linking.

Structure:

Code: Select all

C:\Astrobe\Test
  + P.mod
  + lib
    + Main.mod
  + sub
    S.mod
    + sub0
      S0.mod
Code:

Code: Select all

MODULE P;
  IMPORT Main, S;
END P.

MODULE S;
  IMPORT S0;
END S.

MODULE S0;
END S0.

MODULE Main;
END Main.
Search path:

Code: Select all

lib
sub
sub0
I can compile P.mod sucessfully by a "manual" sequence of separate compilations, in this order: S0, S, Main, P. Linking fails with "Module S0 - not found". This follows from the two rules above. No surprise. Adding 'sub/sub0' to the search path rectifies the situation.

Hence, note to self, a general rule for using relative directory paths to keep in mind is: all modules must be found via relative directory paths from the program main module (importing Main), in addition to the paths required for compilation. The build system also fails to find S0 with the above set of relative directories, but with this general rule for the linker also the build system is happy. :)