curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: c-ares linking problem on Apple, cross-compiling for ARM.

From: Jeffrey Walton via curl-library <curl-library_at_lists.haxx.se>
Date: Wed, 25 Jan 2023 06:51:34 -0500

On Wed, Jan 25, 2023 at 12:46 AM Ben Greear via curl-library
<curl-library_at_lists.haxx.se> wrote:
>
> So, I'm well off in the weeds here.
>
> Trying to compile lib-cares on macos (using clang), for ARM target on x86-64 macos machine. I'm able to see the
> c files compiled for the right target, but the linker part is not passing the -target
> flag it seems.
>
> [...]
> Here is how I am doing the configure step:
>
> (cd c-ares.ct && \
> export CFLAGS="-mmacosx-version-min=11.0 -target arm64-apple-macos11"; \
> export LDFLAGS="-mmacosx-version-min=11.0 -target arm64-apple-macos11"; \
> ./configure --enable-warnings --host=aarch64-apple-darwin && \
> perl -i.bkp -pe 's/^archive_cmds.*\K-install_name/-target arm64-apple-macos11 -install_name/' libtool)

I think there may be two problems. First, I think you should set a
sysroot. Second, I think you should set CPPFLAGS. I would also set
CXXFLAGS for completeness, but I don't believe it's a problem in this
instance. CXXFLAGS will just be ignored if it is not used.

CPPFLAGS will include --isysroot . LDFLAGS will include --sysroot.

Here's what things look like when I set a cross-compile environment
for an iPad from an old Intel MacBook using an old XCode:

$ source ./setenv-ios.sh IOS_SDK=iPhone IOS_CPU=arm64
Configuring for iPhoneOS (arm64)
XCODE_TOOLCHAIN:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/
IOS_SDK: iPhoneOS
IOS_CPU: arm64
IOS_CFLAGS: -arch arm64 -miphoneos-version-min=6 -fno-common
IOS_CXXFLAGS: -arch arm64 -miphoneos-version-min=6 -stdlib=libc++ -fno-common
IOS_SYSROOT: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.2.sdk

$ echo $CPPFLAGS
-DNDEBUG -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.2.sdk
$ echo $CFLAGS
-Wall -g2 -O3 -fPIC -arch arm64 -miphoneos-version-min=6 -fno-common
$ echo $CXXFLAGS
-Wall -g2 -O3 -fPIC -arch arm64 -miphoneos-version-min=6
-stdlib=libc++ -fno-common
$ echo $LDFLAGS
--sysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.2.sdk

You can find the setenv-ios.sh script here:
https://github.com/weidai11/cryptopp/blob/master/TestScripts/setenv-ios.sh
. It will work with any well written makefile or Automake project.
"Well written" means the user's flags are honored, and not stomped on
by the makefile author. I've been using setenv-ios.sh for 10 or 15
years now. It's a little outdated, but it still works fine.

Finally, when you are cross-compiling, you have to set both --host and
--build for configure due to an old bug in Autoconf. Also see
https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Hosts-and-Cross_002dCompilation.html
.

Jeff
-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2023-01-25