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: Jeffrey Walton via curl-library <curl-library_at_cool.haxx.se>
Date: Thu, 12 Nov 2020 11:20:40 -0500

On Thu, Nov 12, 2020 at 10:58 AM Taw via curl-library
<curl-library_at_cool.haxx.se> wrote:
>
> Hi,
> This is my first mail in a mailing-list so I hope I do this properly.
>
> 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. So I put a dummy "--host=arm" and it seems to work.
> 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"?

When cross-compiling, you need to set both --host and --build. I don't
know what the triplet should be. Maybe something like "arm64-apple".
Also see https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Specifying-Target-Triplets.html.

You should set CC, CXX, CPPFLAGS, CFLAGS, CXXFLAGS, AS, ASFLAGS and
LD. CFLAGS and CXXFLAGS should include a --sysroot for the ARM target.
If you use --isysroot, then set it in CPPFLAGS.

You should also build all of the dependencies cURL needs. There are a
lot of them, including Bzip2, Zlib, Unistring, GetText, IDN2, PCRE2,
OpenSSL and OpenLDAP. And NgHttp2 can be a dependency if you have
C++14 support. Also see
https://github.com/noloader/Build-Scripts/blob/master/build-curl.sh.

Autotools projects should use a --prefix of something like
"$HOME/apple-arm64". Your --sysroot and --isysroot would then use
"$HOME/apple-arm64", too.

One of the easier things for you to do is, set up a Hello World
project, and copy the settings from Xcode to your project. A Xcode
build will give you most (not all) of the settings you will need.

Jeff

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