Recent

Author Topic: [SOLVED] MacOSX dont find libX11.dylib  (Read 947 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 3176
    • StrumPract is the musicians best friend
[SOLVED] MacOSX dont find libX11.dylib
« on: January 15, 2024, 01:51:21 pm »
Hello.

I try to compile a application using last release of XQwartz and xlib.pas.
libX11.dylib is located in /usr/X11/lib.

In code there is that in xlib.pas:

Code: Pascal  [Select][+][-]
  1. {linklib libX11.dylib}
  2. const
  3.  libX11='X11';

But strangely, after compilation that is ok, there is a error message at linking:

Quote
Linking demo
ld: library not found -lX11
An error occured while linking
Fatal: There was 1 errors compiling module, stopping.

There is a other strange result: if adding fpc parameter "-Fl/usr/X11/lib", there is that error:

Quote
ld: library not found -lX11.so.6
An error occured while linking
Fatal: There was 1 errors compiling module, stopping.

But libX11.so.6 is a Linux library, why fpc gives that error on Mac?

[EDIT] fpc used is 3.2.2 from installing Lazarus 3.0 package and "Command line tools for Xcode" is installed on MacOs 13.0 Ventura and Xcode is 14.3.1.

[EDIT2] Here a very simple program that fails to link X11:

Code: Pascal  [Select][+][-]
  1. program testxlib;
  2. uses xlib;
  3. begin
  4. end.

Thanks to help.

« Last Edit: January 16, 2024, 02:30:09 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

TRon

  • Hero Member
  • *****
  • Posts: 2663
Re: MacOSX dont find libX11.dylib
« Reply #1 on: January 16, 2024, 04:15:27 am »
Hi Fred,

Note that I can't verify and do not have any experience with macos.

First of all, are you sure about your:
Code: Pascal  [Select][+][-]
  1. {linklib libX11.dylib}
  2.  
Because to be correct it should read:

Code: Pascal  [Select][+][-]
  1. {$linklib libX11.dylib}
  2.  

Secondly (the most obvious one, so don't shoot me but I have to ask to make sure) are you sure you are compiling on/for MacOS ?

Thirdly, as a remark, the library prefix and/or suffix can be set globally with the $LIBPREFIX and $LIBSUFFIX directives. If you have that defined anywhere else (in included units for instance) then your expectations on what the linker actually searches for might be wrong.

Which brings me to to point four  :)

Remember that libraries and their numeric suffix (versioning) is problematic to link against (on Linux) ? Linux uses file-links (usually provided by installing a "-dev" package) to be able to link against the correct version of the library.

So, it might be beneficial to analyze some output from the linker because I suspect that somewhere on your system is a link that points to that specific library in your error message. You can use the option -k to pass something to the linker. Because I do not know which linker macos uses I have no idea what parameter to pass but in case you do know the name of the linker then try invoke it from a shell and try to display its help so that you can figure out what arguments to provide in order to debug the linking process.

BTW, because the xlib.pp file is using static linking should the linker not be searching for libx11.a ?
« Last Edit: January 16, 2024, 04:23:16 am by TRon »

Fred vS

  • Hero Member
  • *****
  • Posts: 3176
    • StrumPract is the musicians best friend
Re: MacOSX dont find libX11.dylib
« Reply #2 on: January 16, 2024, 12:59:38 pm »
Hello Ron and thanks to help.

Code: Pascal  [Select][+][-]
  1. {$linklib libX11.dylib}

Yes, of course, I forgot the "$" here but in code it is ok.
I am using VMWare and Mac OSX 13.0 on it.

All works well, including Lazarus that can compile and run LCL application.

But the problem comes from xlib.pp ( from original fpc source ).

To be able to use X11 libraries on Mac, you need to install XQwartz: https://www.xquartz.org/
The installation of XQwartz is easy, just download the package and install it (you may try, it is easy to remove it if you dont want it anymore).

But the problem comes with linking, just try this if you have a Mac (after installing XQwartz.)
Note that xlib.pp is the original from fpc source.

Code: Pascal  [Select][+][-]
  1.     program testxlib;
  2.     uses xlib;
  3.     begin
  4.     end.

In my case, the compilation is ok but it fails at linking.
Quote
Secondly (the most obvious one, so don't shoot me but I have to ask to make sure) are you sure you are compiling on/for MacOS ?
.
Huh, yes it is why I dont understand why there is that error message from fpc if I use that parameter:  "-Fl/usr/X11/lib",
Quote
ld: library not found -lX11.so.6

It seems to be a Linux error message.

[EDIT] In attachment screenshot of Lazarus working and linking of xlib.pp failing.
« Last Edit: January 16, 2024, 01:26:23 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3176
    • StrumPract is the musicians best friend
Re: MacOSX dont find libX11.dylib
« Reply #3 on: January 16, 2024, 01:54:13 pm »
Re-hello.

I have re-tried the compilation of the simple demo:

 
Code: Pascal  [Select][+][-]
  1.        program testxlib;
  2.         uses xlib;
  3.         begin
  4.         end.

using that fpc parameters (like I did yesterday deep night, but adding -B parameter):

Code: Pascal  [Select][+][-]
  1. > fpc -B -Fl/usr/X11/lib testxlib.pas

And now the compilation + linking is ok (with a warning at linking but ok)! (see screenshot).

So, once again, sorry for the noise (but I knew that with the Mac there are always strange surprises, mainly late in the night, when I am very tired).
[EDIT] There was a msegui unit not yet adapted for Mac that I did not see yesterday.
 Now msegui apps run on the Mac too (but XQwartz must be installed)!

Thanks Ron for helping.

Fre;D
« Last Edit: January 17, 2024, 12:27:20 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

 

TinyPortal © 2005-2018