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 <>
Date: Wed, 25 Jan 2023 06:51:34 -0500

On Wed, Jan 25, 2023 at 12:46 AM Ben Greear via curl-library
<> 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 ./ IOS_SDK=iPhone IOS_CPU=arm64
Configuring for iPhoneOS (arm64)
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/

$ echo $CPPFLAGS
-DNDEBUG -isysroot
$ 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/

You can find the script here:
. 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 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

Received on 2023-01-25