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: Building cURL for Apple Silicon

From: Petr Pisar via curl-library <curl-library_at_cool.haxx.se>
Date: Thu, 12 Nov 2020 17:36:32 +0100

On Thu, Nov 12, 2020 at 05:48:34PM +0200, Taw via curl-library wrote:
> I am trying to build cURL for Apple Silicon ARM (cross-compilation) using a
> macOS Intel host.
> How is done with other libraries (zlib, cjson, etc): just add "-target
> arm64-apple-macos11" to CFLAGS and that's it.
>
> I am using this command
> "CFLAGS=" -fPIC -DPIC -m64 -target arm64-apple-macos11 " ./configure
> --without-libssh2 --without-zlib --without-gnutls --without-nss
> --without-libidn --without-libidn2 --without-nghttp2 --without-librtmp
> --without-brotli --without-libpsl
> --prefix="/Users/test/work/curl-7.73.0/prefix"
> --with-ssl="/Users/test/work/openssl-1.1.1h/prefix/"
>
> I get this error
> "configure:4488: gcc -o conftest -fPIC -DPIC -m64 -target
> arm64-apple-macos11 conftest.c >&5
> configure:4492: $? = 0
> configure:4499: ./conftest
> ./configure: line 4501: ./conftest: Bad CPU type in executable
> configure:4503: $? = 126
> configure:4510: error: in `/Users/test/work/curl-7.73.0':
> configure:4512: error: cannot run C compiled programs.
> If you meant to cross compile, use `--host'."
>
> But I don't know what "--host" to use.

./configure has three options related to a platform:

--build where the executable will be built
--host where the executable will be run
--target what platform will the executable able to process

See
<https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Specifying-Target-Triplets.html>
for more details.

--target option is not used by curl build script. What you did is that you
requested a compiler for Intel platform (no --host), but you commanded the
compiler to produce a code for 64-bit ARM (CFLAGS="-m64 -target
arm64-apple-macos11").

When ./configure run a self test, it used those flags to build a program
and because --build matched --host (you did not provide any of them),
./configure attempted to execute the program. And ARM code does not run on
Intel and thus dynamic linker (or a kernel) refused to execute it.

> So I put a dummy "--host=arm" and it seems to work.

Then ./configure knew that you were crosscompiling and did not attempt to
execute the program.

> On configure I get "Host setup: arm-unknown-none", but after "make
> install" the binary seems ok.
> "prefix/bin/curl: Mach-O 64-bit executable arm64"
>
> Am I doing this in a correct manner? Does it matter what I put to "host"?
>
The correct way is specifying a name of a toolchain that you want to use for
cross-compilation with --host option and putting the compiler options that
selects the optimizations for the architecture into a CFLAGS argument.
Which one it is depends on the compiler and the hardware you cross-compile to.
See a manual of your compiler for the CFLAGS options and a documentation of
the hardware vendor.

I have no experience with MacOS, neither with the new Apple ARM chips, so
I cannot help you more.

-- Petr


-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2020-11-12