Pierre Ossman (Work account) created an issue: 
https://gitlab.com/gnutls/gnutls/-/issues/1775



Cross-compiling for macOS doesn't work, and you end up failing to link the 
library with these errors:

```console
...
ld: warning: ignoring file /usr/lib64/libzstd.so, building for macOS-x86_64 but 
attempting to link with file built for unknown-unsupported file format ( 0x7F 
0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file /usr/lib64/libz.so, building for macOS-x86_64 but 
attempting to link with file built for unknown-unsupported file format ( 0x7F 
0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file /usr/lib64/libgmp.so, building for macOS-x86_64 but 
attempting to link with file built for unknown-unsupported file format ( 0x7F 
0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
...
Undefined symbols for architecture x86_64:
  "_ZSTD_compress", referenced from:
      __gnutls_compress in compress.o
  "_ZSTD_compressBound", referenced from:
      __gnutls_compress_bound in compress.o
...
```

The problem is that the following macro in `configure.ac` is too primitive and 
ends up with the wrong result, confusing ld64 and breaking the link:

```m4
AC_LIB_HAVE_LINKFLAGS(dl,, [#include <dlfcn.h>], [dladdr (0, 0);])
```

This makes a few bad assumptions:

a) That it cannot use `dladdr()` without `libdl` (i.e., it should try looking 
for the symbol without extra libraries)

b) That the link time location of `libdl` matches the runtime location of 
GnuTLS (two bad assumptions in one), which isn't true when cross compiling

End result is that it finds the *Linux* `/usr/lib64/libdl.so` and then blindly 
adds `-L/usr/lib64 -ldl` to the link line.

This then breaks during the link as command line `-L` has priority over the 
default library paths. ld64 happens to be clever enough to adjust things for 
the sysroot, but only for paths that actually exist in the sysroot. And 
`/usr/lib64` does not.


Manually trying to find libraries rather than trusting the compiler/environment 
is very rude behaviour IMHO. I would suggest replacing this with 
`AC_SEARCH_LIBS()`. Possibly with some override if there is a need to support 
weird setups.

-- 
Reply to this email directly or view it on GitLab: 
https://gitlab.com/gnutls/gnutls/-/issues/1775
You're receiving this email because of your account on gitlab.com.


_______________________________________________
Gnutls-devel mailing list
[email protected]
http://lists.gnupg.org/mailman/listinfo/gnutls-devel
  • [gnutls-de... Read-only notification of GnuTLS library development activities
    • Re: [... Read-only notification of GnuTLS library development activities

Reply via email to