Recent

Author Topic: .dylib static loading  (Read 740 times)

lelebass

  • New Member
  • *
  • Posts: 36
.dylib static loading
« on: April 28, 2020, 12:42:12 pm »
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. :o

Daniele

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8611
  • FPC developer.
Re: .dylib static loading
« Reply #1 on: April 28, 2020, 03:32:30 pm »
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

  • New Member
  • *
  • Posts: 36
Re: .dylib static loading
« Reply #2 on: April 28, 2020, 05:14:43 pm »
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
« Last Edit: April 28, 2020, 05:56:22 pm by lelebass »

trev

  • Hero Member
  • *****
  • Posts: 837
  • Former Delphi 1-7 and 10.2 User
Re: .dylib static loading
« Reply #3 on: April 29, 2020, 10:08:37 am »
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

Does adding the library path (see attached image) help?
o Lazarus v2.1.0 r63598, FPC v3.3.1 r45778, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (Parallels VM)
o FPC 3.0.4, FreeBSD 12-STABLE r361007 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

lelebass

  • New Member
  • *
  • Posts: 36
Re: .dylib static loading
« Reply #4 on: April 29, 2020, 11:53:42 am »
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

  • Hero Member
  • *****
  • Posts: 837
  • Former Delphi 1-7 and 10.2 User
Re: .dylib static loading
« Reply #5 on: April 29, 2020, 02:13:34 pm »
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.
o Lazarus v2.1.0 r63598, FPC v3.3.1 r45778, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (Parallels VM)
o FPC 3.0.4, FreeBSD 12-STABLE r361007 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

lelebass

  • New Member
  • *
  • Posts: 36
Re: .dylib static loading
« Reply #6 on: April 30, 2020, 06:59:50 am »
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][+][-]
  1. [0.006] (11033) interpreting file option "# searchpath for libraries"
  2. [0.006] (11033) interpreting file option "#-Fl/usr/local/lib/fpc/3.0.4/lib"
  3. [0.006] (11033) interpreting file option "#-Fl/lib;/usr/lib"
  4. [0.006] (11028) Handling option "-Fl/usr/local/lib/fpc/3.0.4/lib/x86_64-darwin"
  5. [0.006] (11032) interpreting option "-Fl/usr/local/lib/fpc/3.0.4/lib/x86_64-darwin"
  6. [0.006] Path "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/lib/fpc/3.0.4/lib/x86_64-darwin/" not found
  7.  

I also checked from Project Options -> Show Options:

Code: Text  [Select][+][-]
  1. '/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][+][-]
  1. [0.063] (9015) Linking /Users/steve/Desktop/Link_Test/linktest
  2. [0.064] Searching file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/crt1.10.5.o... found
  3. [0.064] Searching file /Library/Developer/CommandLineTools/usr/bin/ld... found
  4. [0.064] (9017) Using util /Library/Developer/CommandLineTools/usr/bin/ld
  5. ld: library not found for -lftd2xx
  6. An error occurred while linking
  7. [0.064] Executing "/Users/steve/Desktop/Link_Test/ppaslink.sh " with fpSystem call
  8. [0.080] linktest.pas(8) Error: (9013) Error while linking
  9. [0.080] linktest.pas(8) Fatal: (10026) There were 1 errors compiling module, stopping
  10. [0.080] Fatal: (1018) Compilation aborted
  11. Error: /usr/local/bin/ppcx64 returned an error exit-code

Daniele
« Last Edit: April 30, 2020, 04:38:08 pm by lelebass »

trev

  • Hero Member
  • *****
  • Posts: 837
  • Former Delphi 1-7 and 10.2 User
Re: .dylib static loading
« Reply #7 on: April 30, 2020, 09:10:28 am »
Curious. Do you not get in the verbose output:

Code: [Select]
...Handling option "-Fl/usr/local/lib"
...Interpreting option "-Fl/usr/local/lib"
o Lazarus v2.1.0 r63598, FPC v3.3.1 r45778, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (Parallels VM)
o FPC 3.0.4, FreeBSD 12-STABLE r361007 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

 

TinyPortal © 2005-2018