.dylib static loading lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- lelebass · 2020-04-28 10:42 I am using Lazarus 2.0.8 x86_64-Darwin-Cocoa on Mojave and I came across a problem. In my application I am using static loading of a .dylib using the method reported in the documentation: https://wiki.freepascal.org/Lazarus/FPC_Libraries#External_- _statically_loading_a_dynamic_library basically I am using the following line of code to instruct the linker: {$linklib ftd2xx} the actual library is installed in /usr/local/lib in form of a .dylib and a symbolic link. libftd2xx.1.2.2.dylib libftd2xx.dylib -> /usr/local/lib/libftd2xx.1.2.2.dylib with previous versions of Lazarus 1.8.4 (Carbon) I had no problems and project compiled without errors. Now I get this error at compilation: Compile Project, Target: linktest: Exit code 1, Errors: 1 Linking /Users/steve/Desktop/Link_Test/linktest ld: library not found for -lftd2xx An error occurred while linking linktest.lpr(23,0) Error: Error while linking After some attempts I found out that copying the symbolic link into the project folder makes the linker happy and I was able to compile. I wonder if this workaround is harmless. During these attempts I've also noticed something which is still not clear to me, it looks like the linker is considering the following statements equivalent: {$linklib libftd2xx.dylib} {$linklib libftd2xx} {$linklib ftd2xx.dylib} {$linklib ftd2xx} I wasn't able to find information on this on the Free Pascal documentation, but looking at the example reported in the Free Pascal Wiki there are some cues: {$ifdef win32}   gtklib = 'libgtk-win32-2.0-0.dll'; {$else}   {$ifdef darwin}     gtklib = 'gtk-x11-2.0';     {$linklib gtk-x11-2.0}   {$else}     gtklib = 'libgtk-x11-2.0.so';   {$endif} {$endif} where in the darwin case the "lib" looks is missing from the names. Daniele ---------------------------------------------------------------------- marcov · 2020-04-28 13:32 Since the old application is 32-bit, and the new one is 64-bit, did you also make sure the said library is 64-bit? ---------------------------------------------------------------------- lelebass · 2020-04-28 15:14 Yes, I checked: Steves-MacBook-Pro:~ steve$ file /usr/local/lib/libftd2xx.1.2.2.dylib /usr/local/lib/libftd2xx.1.2.2.dylib: Mach-O universal binary with 3 architectures: [i386:Mach-O dynamically linked shared library i386] [ppc_7400:Mach-O dynamically linked shared library ppc_7400] /usr/local/lib/libftd2xx.1.2.2.dylib (for architecture i386):   Mach-O dynamically linked shared library i386 /usr/local/lib/libftd2xx.1.2.2.dylib (for architecture x86_64):   Mach-O 64-bit dynamically linked shared library x86_64 /usr/local/lib/libftd2xx.1.2.2.dylib (for architecture ppc7400):   Mach-O dynamically linked shared library ppc_7400 the library is 32 and 64 bit and in fact working using the aforementioned workaround. Daniele ---------------------------------------------------------------------- trev · 2020-04-29 08:08 Quote from: lelebass on April 28, 2020, 12:42:12 pmCompile Project, Target: linktest: Exit code 1, Errors: 1 Linking /Users/steve/Desktop/Link_Test/linktest ld: library not found for -lftd2xx An error occurred while linking linktest.lpr(23,0) Error: Error while linking Does adding the library path (see attached image) help? ---------------------------------------------------------------------- lelebass · 2020-04-29 09:53 Dear Trev, thank you for your response. Adding the library path does not seem to solve the problem.  I am still getting the error: ld: library not found for -lftd2xx Ciao, Daniele ---------------------------------------------------------------------- trev · 2020-04-29 12:13 Try showing everything during the compilation - see attached image. Compile and then copy all from the messages window (right-click, copy all) and paste into TextEdit or whatever. This should reveal where it's looking for the library. ---------------------------------------------------------------------- lelebass · 2020-04-30 04:59 Thank you again Trev. With the /usr/local/lib/ library path added in the Project Options I get the attached output. I guess the interesting part is: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i [0.006] (11033) interpreting file option "# searchpath for libraries"[0.006] (11033) interpreting file option "#-Fl/usr/local/lib/fpc/3.0.4/lib"[0.006] (11033) interpreting file option "#-Fl/lib;/usr/lib"[0.006] (11028) Handling option "-Fl/usr/local/lib/fpc/3.0.4/lib/x86_64-darwin"[0.006] (11032) interpreting option "-Fl/usr/local/lib/fpc/3.0.4/lib/x86_64-darwin"[0.006] Path "/Library/ Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/lib/fpc/3.0.4/lib /x86_64-darwin/" not found  I also checked from Project Options -> Show Options: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i '/usr/local/bin/fpc'  -MObjFPC -Scghi -O1 -gw -gl -l -vabq -Filib/x86_64-darwin -Fl/usr/local/lib -Fu. -FUlib/x86_64-darwin -FE. -olinktest Where it looks like the -FI/usr/local/lib is correctly instructing the linker, but with no luck: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i [0.063] (9015) Linking /Users/steve/Desktop/Link_Test/linktest[0.064] Searching file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr /lib/crt1.10.5.o... found[0.064] Searching file /Library/Developer/CommandLineTools/usr/bin/ld... found[0.064] (9017) Using util /Library/Developer/CommandLineTools/usr/bin/ldld: library not found for -lftd2xxAn error occurred while linking [0.064] Executing "/Users/steve/Desktop/Link_Test/ppaslink.sh " with fpSystem call[0.080] linktest.pas(8) Error: (9013) Error while linking[0.080] linktest.pas(8) Fatal: (10026) There were 1 errors compiling module, stopping[0.080] Fatal: (1018) Compilation abortedError: /usr/local/bin/ppcx64 returned an error exit-code Daniele ---------------------------------------------------------------------- trev · 2020-04-30 07:10 Curious. Do you not get in the verbose output: Code: [Select]...Handling option "-Fl/usr/local/lib" ...Interpreting option "-Fl/usr/local/lib"