Recent

Author Topic: [SOLVED] matrix unit not found  (Read 3440 times)

apeoperaio

  • Full Member
  • ***
  • Posts: 158
[SOLVED] matrix unit not found
« on: May 25, 2018, 01:32:35 pm »
I have a project using matrix unit (https://www.freepascal.org/docs-html/rtl/matrix/index.html) but I have problems using it on my Mac (fpc 3.0.4 lazarus 1.8.2).
If I add the matrix unit to my application it is not found correctly, instead of matrix unit lazarus points to a matrix.pp program located in fpcsrc/tests/bench/shootout/obsolete/matrix.pp
Both using carbon or cocoa. I got it even with a new project.

Here a snippet of the program that lazarus found instead of matrix unit.
Code: Pascal  [Select]
  1. { Matrix Multiplication }
  2.  
  3. program matrix;
  4. uses SysUtils;
  5.  
  6. const
  7.     size = 30;
  8.  
  9. type tMatrix = array[0..size, 0..size] of longint;        

Any hint?
« Last Edit: May 28, 2018, 12:22:27 pm by apeoperaio »

Thaddy

  • Hero Member
  • *****
  • Posts: 9152
Re: matrix unit not found
« Reply #1 on: May 25, 2018, 01:45:12 pm »
If you need a unit called matrix, don't call your program matrix....
also related to equus asinus.

apeoperaio

  • Full Member
  • ***
  • Posts: 158
Re: matrix unit not found
« Reply #2 on: May 25, 2018, 01:49:22 pm »
And I don't.
I just create a new application (project1) and here it is the source:

Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, matrix;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.   private
  13.     ms: Tmatrix3_single;
  14.   public
  15.  
  16.   end;
  17.  
  18. var
  19.   Form1: TForm1;
  20.  
  21. implementation
  22.  
  23. {$R *.lfm}
  24.  
  25. end.
  26.  

If I try to navigate to matrix unit the matrix.pp program source is opened.

ccrause

  • Full Member
  • ***
  • Posts: 185
Re: matrix unit not found
« Reply #3 on: May 25, 2018, 02:35:21 pm »
I have a project using matrix unit (https://www.freepascal.org/docs-html/rtl/matrix/index.html) but I have problems using it on my Mac (fpc 3.0.4 lazarus 1.8.2).

Any hint?
The source is located here: [fpc source dir]\packages\rtl-extra\src\inc
On my Lazarus with FPC bundled install the compiled unit is located here: [fpc compiled units dir]\x86_64-win64\rtl-extra

How did you install FPC (package manager, compile from source ...)? To me it seems as if the rtl-extra package isn't installed on your Mac.

wp

  • Hero Member
  • *****
  • Posts: 6310
Re: matrix unit not found
« Reply #4 on: May 25, 2018, 02:40:10 pm »
If I try to navigate to matrix unit the matrix.pp program source is opened.
matrix.pp is not a program, but a unit.

How do you navigate? If you CTRL+click on the name of the unit "matrix" the IDE will open the source file of unit matrix.pp at the top.
If you CTRL+click on the word "tmatrix3_single" in your code the IDE will jump to the implementation (or interface) of this type. It is in matrix.pp, too.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

apeoperaio

  • Full Member
  • ***
  • Posts: 158
Re: matrix unit not found
« Reply #5 on: May 25, 2018, 04:29:57 pm »
I navigate using CTRL+click, if I CTRL+click on the name of matrix unit matrix.pp is opened (/usr/local/share/fpcsrc/tests/bench/shootout/obsolete/matrix.pp). See image.

If I CTRL+click on tmatrix3_single nothing happen.

I installed lazarus (1.8.2) and fpc (3.0.4) from source forge (https://sourceforge.net/projects/lazarus/files/Lazarus%20Mac%20OS%20X%20i386/Lazarus%201.8.2/). All the 3 dmg files.
Everything works as expected (I am using it for production) except this strange behaviour for matrix unit.

If I navigate through terminal I can find the correct matrix.pp here [fpc source dir]/packages/rtl-extra/src/inc, lazarus doesn't.


apeoperaio

  • Full Member
  • ***
  • Posts: 158
Re: matrix unit not found
« Reply #6 on: May 25, 2018, 04:37:25 pm »
If I do this:

uses
  matrix in ''/usr/local/share/fpcsrc/packages/rtl-extra/src/inc/matrix.pp'';

Ctrl+click works as expected both for matrix name and tmatrix3_single.

Eventually there are variable that could I use instead of specifying the whole absolute path?

wp

  • Hero Member
  • *****
  • Posts: 6310
Re: matrix unit not found
« Reply #7 on: May 25, 2018, 05:33:22 pm »
Which paths are specified in "Options" > "Compiler options" > "Paths" of your project?

When I create a new project in Lazarus ("File" > "New" > "Project" > "Simple program") the path "Other unit files" is empty. And the following program compiles and runs correctly, and CTRL+Click on TMatrix3_single leads to the correct file:

Code: Pascal  [Select]
  1. program Project1;
  2.  
  3. uses
  4.   matrix;
  5.  
  6. var
  7.   m: Tmatrix3_single;
  8.  
  9. begin
  10.   m.Init(11, 12, 13, 21, 22, 23, 31, 32, 33);
  11.   WriteLn(m.data[0,0]:0:3);
  12.   ReadLn;
  13. end.

Moreover, look at the paths shown in fpc.cfg. Your path /usr/local/share/fpcsrc/tests/bench/shootout/obsolete (or part of it) should not be mentioned.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

apeoperaio

  • Full Member
  • ***
  • Posts: 158
Re: matrix unit not found
« Reply #8 on: May 25, 2018, 06:19:43 pm »
Which paths are specified in "Options" > "Compiler options" > "Paths" of your project?

It is empty.

When I create a new project in Lazarus ("File" > "New" > "Project" > "Simple program") the path "Other unit files" is empty. And the following program compiles and runs correctly, and CTRL+Click on TMatrix3_single leads to the correct file:

It compiles and runs fine even here but CTRL+Click on TMatrix3_single does not open anything.

Below fpc.cfg located in /private/etc/fpc.cfg

Code: Pascal  [Select]
  1. #
  2. # Config file generated by fpcmkcfg on 27-3-18 - 18:25:06
  3. # Example fpc.cfg for Free Pascal Compiler
  4. #
  5.  
  6. # ----------------------
  7. # Defines (preprocessor)
  8. # ----------------------
  9.  
  10. #
  11. # nested #IFNDEF, #IFDEF, #ENDIF, #ELSE, #DEFINE, #UNDEF are allowed
  12. #
  13. # -d is the same as #DEFINE
  14. # -u is the same as #UNDEF
  15. #
  16.  
  17. #
  18. # Some examples (for switches see below, and the -? helppages)
  19. #
  20. # Try compiling with the -dRELEASE or -dDEBUG on the commandline
  21. #
  22.  
  23. # For a release compile with optimizes and strip debuginfo
  24. #IFDEF RELEASE
  25.   -O2
  26.   -Xs
  27.   #WRITE Compiling Release Version
  28. #ENDIF
  29.  
  30. # For a debug version compile with debuginfo and all codegeneration checks on
  31. #IFDEF DEBUG
  32.   -gl
  33.   -Crtoi
  34.   #WRITE Compiling Debug Version
  35. #ENDIF
  36.  
  37. # assembling
  38. #ifdef darwin
  39. # use pipes instead of temporary files for assembling
  40. -ap
  41. # path to Xcode 4.3+ utilities (no problem if it doesn't exist)
  42. -FD/Applications/Xcode.app/Contents/Developer/usr/bin
  43. #endif
  44.  
  45. # ----------------
  46. # Parsing switches
  47. # ----------------
  48.  
  49. # Pascal language mode
  50. #      -Mfpc      free pascal dialect (default)
  51. #      -Mobjfpc   switch some Delphi 2 extensions on
  52. #      -Mdelphi   tries to be Delphi compatible
  53. #      -Mtp       tries to be TP/BP 7.0 compatible
  54. #      -Mgpc      tries to be gpc compatible
  55. #      -Mmacpas   tries to be compatible to the macintosh pascal dialects
  56. #
  57. # Turn on Object Pascal extensions by default
  58. #-Mobjfpc
  59.  
  60. # Assembler reader mode
  61. #      -Rdefault  use default assembler
  62. #      -Ratt      read AT&T style assembler
  63. #      -Rintel    read Intel style assembler
  64. #
  65. # All assembler blocks are AT&T styled by default
  66. #-Ratt
  67.  
  68. # Semantic checking
  69. #      -S2        same as -Mobjfpc
  70. #      -Sc        supports operators like C (*=,+=,/= and -=)
  71. #      -Sa        include assertion code.
  72. #      -Sd        same as -Mdelphi
  73. #      -Se<x>     error options. <x> is a combination of the following:
  74. #         <n> : compiler stops after <n> errors (default is 1)
  75. #         w   : compiler stops also after warnings
  76. #         n   : compiler stops also after notes
  77. #         h   : compiler stops also after hints
  78. #      -Sg        allow LABEL and GOTO
  79. #      -Sh        Use ansistrings
  80. #      -Si        support C++ styled INLINE
  81. #      -Sk        load fpcylix unit
  82. #      -SI<x>     set interface style to <x>
  83. #         -SIcom    COM compatible interface (default)
  84. #         -SIcorba  CORBA compatible interface
  85. #      -Sm        support macros like C (global)
  86. #      -So        same as -Mtp
  87. #      -Sp        same as -Mgpc
  88. #      -Ss        constructor name must be init (destructor must be done)
  89. #      -Sx        enable exception keywords (default in Delphi/ObjFPC modes)
  90. #
  91. # Allow goto, inline, C-operators, C-vars
  92. -Sgic
  93.  
  94. # ---------------
  95. # Code generation
  96. # ---------------
  97.  
  98. # Uncomment the next line if you always want static/dynamic units by default
  99. # (can be overruled with -CD, -CS at the commandline)
  100. #-CS
  101. #-CD
  102.  
  103. # Set the default heapsize to 8Mb
  104. #-Ch8000000
  105.  
  106. # Set default codegeneration checks (iocheck, overflow, range, stack)
  107. #-Ci
  108. #-Co
  109. #-Cr
  110. #-Ct
  111.  
  112. # Optimizer switches
  113. # -Os        generate smaller code
  114. # -Oa=N      set alignment to N
  115. # -O1        level 1 optimizations (quick optimizations, debuggable)
  116. # -O2        level 2 optimizations (-O1 + optimizations which make debugging more difficult)
  117. # -O3        level 3 optimizations (-O2 + optimizations which also may make the program slower rather than faster)
  118. # -Oo<x>     switch on optimalization x. See fpc -i for possible values
  119. # -OoNO<x>   switch off optimalization x. See fpc -i for possible values
  120. # -Op<x>     set target cpu for optimizing, see fpc -i for possible values
  121.  
  122. #ifdef darwin
  123. #ifdef cpui386
  124. -Cppentiumm
  125. -Oppentiumm
  126. #endif
  127. #endif
  128.  
  129. # -----------------------
  130. # Set Filenames and Paths
  131. # -----------------------
  132.  
  133. # Both slashes and backslashes are allowed in paths
  134.  
  135. # path to the messagefile, not necessary anymore but can be used to override
  136. # the default language
  137. #-Fr/usr/local/lib/fpc/$fpcversion/msg/errore.msg
  138. #-Fr/usr/local/lib/fpc/$fpcversion/msg/errorn.msg
  139. #-Fr/usr/local/lib/fpc/$fpcversion/msg/errores.msg
  140. #-Fr/usr/local/lib/fpc/$fpcversion/msg/errord.msg
  141. #-Fr/usr/local/lib/fpc/$fpcversion/msg/errorr.msg
  142.  
  143. # search path for unicode binary files (FPC 2.x does not know this switch)
  144. #ifndef VER2
  145. -FM/usr/local/lib/fpc/../../share/fpc/$fpcversion/unicode/
  146. #endif
  147.  
  148. # searchpath for units and other system dependent things
  149. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget
  150. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/*
  151. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/rtl
  152.  
  153. #ifdef cpui8086
  154. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/$fpcsubarch-$fpcmemorymodel
  155. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/$fpcsubarch-$fpcmemorymodel/*
  156. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/$fpcsubarch-$fpcmemorymodel/rtl
  157. #endif
  158.  
  159. #IFDEF FPCAPACHE_1_3
  160. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/httpd13/
  161. #ELSE
  162. #IFDEF FPCAPACHE_2_0
  163. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/httpd20
  164. #ELSE
  165. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/httpd22
  166. #ENDIF
  167. #ENDIF
  168.  
  169. # searchpath for fppkg user-specific packages
  170. -Fu~/.fppkg/lib/fpc/$fpcversion/units/$FPCTARGET/*
  171.  
  172. # path to the gcclib
  173. #ifdef cpui386
  174. -Fl/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/lib/darwin17.4.0
  175. #endif
  176. #ifdef cpux86_64
  177. -Fl/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/lib/darwin17.4.0
  178. #endif
  179. #ifdef cpupowerpc
  180. -Fl/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/lib/darwin17.4.0
  181. #endif
  182. #ifdef cpupowerpc64
  183. -Fl/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/lib/darwin17.4.0
  184. #endif
  185.  
  186. # searchpath for libraries
  187. #-Fl/usr/local/lib/fpc/$fpcversion/lib
  188. #-Fl/lib;/usr/lib
  189. -Fl/usr/local/lib/fpc/$fpcversion/lib/$FPCTARGET
  190.  
  191. # searchpath for tools
  192. -FD/usr/local/lib/fpc/$fpcversion/bin/$FPCTARGET
  193.  
  194. #IFNDEF Darwin
  195. #DEFINE NEEDCROSSBINUTILS
  196. #ENDIF
  197.  
  198. # never need cross-prefix when targeting the JVM
  199. # (no native compiler, always cross-compiling)
  200. #ifdef cpujvm
  201. #undef NEEDCROSSBINUTILS
  202. #endif
  203.  
  204. # for android cross-prefix is set by compiler
  205. #ifdef android
  206. #undef NEEDCROSSBINUTILS
  207. #endif
  208.  
  209. # never need cross-prefix when targeting the i8086
  210. # (no native compiler, always cross-compiling)
  211. #ifdef cpui8086
  212. #undef NEEDCROSSBINUTILS
  213. #endif
  214.  
  215. # never need cross-prefix when targeting the i8086
  216. # (no native compiler, always cross-compiling)
  217. #ifdef cpujvm
  218. #undef NEEDCROSSBINUTILS
  219. #endif
  220.  
  221. # binutils prefix for cross compiling
  222. #IFDEF FPC_CROSSCOMPILING
  223. #IFDEF NEEDCROSSBINUTILS
  224.  -XP$FPCTARGET-
  225. #ENDIF
  226. #ENDIF
  227.  
  228.  
  229. # -------------
  230. # Linking
  231. # -------------
  232.  
  233. # generate always debugging information for GDB (slows down the compiling
  234. # process)
  235. #      -gc        generate checks for pointers
  236. #      -gd        use dbx
  237. #      -gg        use gsym
  238. #      -gh        use heap trace unit (for memory leak debugging)
  239. #      -gl        use line info unit to show more info for backtraces
  240. #      -gv        generates programs tracable with valgrind
  241. #      -gw        generate dwarf debugging info
  242. #
  243. # Enable debuginfo and use the line info unit by default
  244. #-gl
  245.  
  246. # always pass an option to the linker
  247. #-k-s
  248.  
  249. # Always strip debuginfo from the executable
  250. -Xs
  251.  
  252. # Always use smartlinking on i8086, because the system unit exceeds the 64kb
  253. # code limit
  254. #ifdef cpui8086
  255. -CX
  256. -XX
  257. #endif
  258.  
  259.  
  260. # -------------
  261. # Miscellaneous
  262. # -------------
  263.  
  264. # Write always a nice FPC logo ;)
  265. -l
  266.  
  267. # Verbosity
  268. #      e : Show errors (default)       d : Show debug info
  269. #      w : Show warnings               u : Show unit info
  270. #      n : Show notes                  t : Show tried/used files
  271. #      h : Show hints                  s : Show time stamps
  272. #      i : Show general info           q : Show message numbers
  273. #      l : Show linenumbers            c : Show conditionals
  274. #      a : Show everything             0 : Show nothing (except errors)
  275. #      b : Write file names messages   r : Rhide/GCC compatibility mode
  276. #          with full path              x : Executable info (Win32 only)
  277. #      v : write fpcdebug.txt with     p : Write tree.log with parse tree
  278. #          lots of debugging info
  279. #
  280. # Display Info, Warnings and Notes
  281. -viwn
  282. # If you don't want so much verbosity use
  283. #-vw

Thaddy

  • Hero Member
  • *****
  • Posts: 9152
Re: matrix unit not found
« Reply #9 on: May 25, 2018, 08:38:03 pm »
Ok reverse my answer
"If you need a unit called matrix, don't call your program matrix...."
Instead:
Search for a program file called "program matrix;" (with find in files...) and delete it.
Problem solved.

Actually I suspect this is a small bug in Lazarus: lpr and lpi (project files) are handled correctly, but .pp and .pas files can also be programs...... Who'll pick it up?

Note that anyway you or someone who has access to your computer wrote a program called matrix....Rename it or delete it.
Even worse: it is probably in your sourcecode root directory, otherwise Laz would pick up the unit, not the program .....< Uhh, I politely ask to re-introduce grumpy ...  >:D >:D >:D  O:-)>
« Last Edit: May 25, 2018, 08:47:50 pm by Thaddy »
also related to equus asinus.

wp

  • Hero Member
  • *****
  • Posts: 6310
Re: matrix unit not found
« Reply #10 on: May 25, 2018, 08:45:10 pm »
Ok reverse my answer
"If you need a unit called matrix, don't call your program matrix...."
Instead:
Search for a program file called "program matrix" (with find in files...) and delete it.
Problem solved.

Actually I suspect this is a small bug in Lazarus: lpr and lpi (project files) are handled correctly, but .pp and .pas files can also be programs...... Who'll pick it up?

Note that anyway you or someone who has access to your computer wrote a program called matrix....
Really? If there is a program "matrix.pp" somewhere on my disk how will Lazarus/fpc be able to find it? I still believe that something is messed up in the paths of OP's installation.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Thaddy

  • Hero Member
  • *****
  • Posts: 9152
Re: matrix unit not found
« Reply #11 on: May 25, 2018, 08:51:42 pm »
No. I can repeat it and reproduce it on at least three platforms: write a
Code: Pascal  [Select]
  1. program matrix;begin end.
is enough. On all platforms. Write it with "copy con" on windows or fp or vim on linux and save it with extension .pp or .pas . Then start something like *his* project in Laz and in the same directory: F*cked up...
Lazarus relies too much on the silly .lpi file....

Which matrix.pp will come first? Come on, you know which....

But *he* must have written that first, get it? And it is the sourcecode, not any binary.
« Last Edit: May 25, 2018, 09:07:22 pm by Thaddy »
also related to equus asinus.

wp

  • Hero Member
  • *****
  • Posts: 6310
Re: matrix unit not found
« Reply #12 on: May 25, 2018, 09:05:08 pm »
Then start something like *his* project in Laz and in the same directory.
Up in reply #5 the OP writes that the guilty matrix.pp is in /usr/local/share/fpcsrc/tests/bench/shootout/obsolete/matrix.pp. This is a folder belonging to fpc and certainly NOT his project folder.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Thaddy

  • Hero Member
  • *****
  • Posts: 9152
Re: matrix unit not found
« Reply #13 on: May 25, 2018, 09:09:00 pm »
Well  /usr/local/share/fpcsrc/tests/bench/shootout/obsolete/matrix.pp is a program.... And I don't even have it.... (well that's funny.... :o )
Since there is no lpi for that program and his path is somehow pointing to that path *before* his library paths things get f*cked up.
And if you reproduce my steps you know why.
« Last Edit: May 25, 2018, 09:11:47 pm by Thaddy »
also related to equus asinus.

wp

  • Hero Member
  • *****
  • Posts: 6310
Re: matrix unit not found
« Reply #14 on: May 26, 2018, 01:02:53 am »
The issue has been fixed in Laz trunk by Mattias Gaertner. It was an issue in codetools.

apeoperaio, if you want to patch your Lazarus version 1.8.2, you should do this:
  • In folder components/codetools/ open the file fpcsrcrules.inc
  • Immediately after line 13 (Score:=-10) add the line Add('tests');
  • Save and recompile the IDE.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10