Hello Everyone,
I am trying to cross compile a swift library using swift version 5.6.2 on ubuntu 20.04 for a 32-bit arm linux system. The swift library that I am building depends on a system library that is found in the sysroot for the target system. There is also a version for the host in /usr/local/lib.
If I try and build for the target using swift build everything works fine:
swift build --destination destination.json
...
Build complete! (4.27s)
However, when I try to cross-compile the tests, it finds the host library and fails to link:
swift build --build-tests --destination destination.json
Building for debugging...
ld.lld: error: /usr/local/lib/<hostlib>.so is incompatible with elf32-littlearm
ld.lld: error: /usr/local/lib/<hostlib>.so is incompatible with elf32-littlearm
ld.lld: error: /usr/local/lib/<hostlib>.so is incompatible with elf32-littlearm
ld.lld: error: /usr/local/lib/<hostlib>.so is incompatible with elf32-littlearm
ld.lld: error: /usr/local/lib/<hostlib>.so is incompatible with elf32-littlearm
ld.lld: error: /usr/local/lib/l<hostlib>.so is incompatible with elf32-littlearm
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
In order to ensure that pkgconfig isn't finding the wrong .pc file for the system library, I have added the pkgconfig directory for the target to the PKG_CONFIG_PATH environment variable:
PKG_CONFIG_PATH="/dir/to/sysroot/usr/lib/pkgconfig" swift build --build-tests --destination.json
and I get similar results. I have also deleted the pkgconfig file in /usr/local/lib/pkgconfig just in case and it still finds the host lib. I then executed the build using some verbose flags and I found some weird flags being passed to swiftc:
/path/to/usr/bin/swiftc -L/usr/local/lib ...
I don't suppose anyone has run into anything similar or knows if I am doing anything wrong?