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: Ben Greear via curl-library <curl-library_at_lists.haxx.se>
Date: Wed, 25 Jan 2023 06:37:33 -0800

On 1/25/23 3:51 AM, Jeffrey Walton wrote:
> 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:

Thanks for the suggestion. I'm pretty sure it is not a problem with setting C*FLAGS,
since those show up as expected in sysroot. I think '-target' is treated special
somehow and ignored, though I cannot find exactly why/where that is happening.

Even after my hack yesterday I found another problem though, and that is the libraries
like 'openssl' that I was getting from 'mac ports' project
are of course built for the host CPU so won't link into the m1 compiled code.

Do you know if there is an easy way to install ports for a non-native CPU? I'm guessing not, and that
my best way forward is just to buy another m1 macos machine and build directly on it.
But, if you know a way, please let me know.

Thanks,
Ben

>
> $ 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
>


-- 
Ben Greear <greearb_at_candelatech.com>
Candela Technologies Inc  http://www.candelatech.com
-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2023-01-25