Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross compiling under OSX is broken #331

Open
apowers313 opened this issue Jan 7, 2018 · 6 comments
Open

Cross compiling under OSX is broken #331

apowers313 opened this issue Jan 7, 2018 · 6 comments

Comments

@apowers313
Copy link

I'm attempting to cross-compile for an Android (Linux) ARM target from an OSX host. Around line 238 of the configure script, there seems to be a bad assumption about only using libtool if you're on OSX / Darwin:

  Darwin* | darwin*)
             shared_ext='.dylib'
             SHAREDLIB=libz$shared_ext
             SHAREDLIBV=libz.$VER$shared_ext
             SHAREDLIBM=libz.$VER1$shared_ext
             LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"}
             if libtool -V 2>&1 | grep Apple > /dev/null; then
                 AR="libtool"
             else
                 AR="/usr/bin/libtool"
             fi
             ARFLAGS="-o" ;;

Since OSX's libtool doesn't understand ELF executables, the build eventually fails with:

libtool -o libz.a adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: adler32.o is not an object file (not allowed in a library)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: crc32.o is not an object file (not allowed in a library)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: deflate.o is not an object file (not allowed in a library)
[ ... snip ... ]
make: *** [libz.a] Error 1

@itank
Copy link

itank commented Mar 26, 2018

I have the same problem, after running following commands I'm able to successfully run tests for libtool.

ar cru libz.a adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
ranlib libz.a

@srijs
Copy link

srijs commented Aug 26, 2018

It looks like you can set the CHOST environment variable to your target triple to get the right behaviour: https://github.com/madler/zlib/blob/master/configure#L33

@terinjokes
Copy link

Similarly, if you're cross-compiling to macOS, the configure script tries libtool from your path, instead of ${CROSS_PREFIX}libtool, resulting in a hardcoded /usr/bin/libtool.

@Lubak
Copy link

Lubak commented Jan 4, 2021

Similarly, if you're cross-compiling to macOS, the configure script tries libtool from your path, instead of ${CROSS_PREFIX}libtool, resulting in a hardcoded /usr/bin/libtool.

Where is CROSS_PREFIX defined?

@Neustradamus
Copy link

Neustradamus commented Jan 19, 2024

Dear all,

Can you test the current devel branch?

What are your results?

Thanks in advance.

@bitmold
Copy link

bitmold commented Apr 8, 2024

Cross compiling on the latest code in the develop branch still breaks things.

/.../Library/Android/sdk/ndk/25.2.9519653//toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android21-clang -fbuild-session-timestamp=1234567890 -fdebug-compilation-dir . -no-canonical-prefixes   -Os -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o gzwrite.o gzwrite.c
libtool -o libz.a adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o 
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: adler32.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: crc32.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: deflate.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: infback.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: inffast.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: inflate.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: inftrees.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: trees.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: zutil.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: compress.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: uncompr.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: gzclose.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: gzlib.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: gzread.o is not an object file (not allowed in a library)
error: /Library/Developer/CommandLineTools/usr/bin/libtool: file: gzwrite.o is not an object file (not allowed in a library)
make[1]: *** [libz.a] Error 1
make: *** [zlib-build-stamp] Error 2

I'm cross compiling with a mac targeting an android/linux system (in this case ABI arm64-v8a...)

As you can see zlib's code is compiled with the current Android NDK but then is linked with my mac's libtool which fails.

Similarly, if you're cross-compiling to macOS, the configure script tries libtool from your path, instead of ${CROSS_PREFIX}libtool, resulting in a hardcoded /usr/bin/libtool.

The problem is the exactly as @terinjokes stated 3.5 years ago.

I tore up the makefile by hand and successfully got my zlib.a file by hardcoding in the llvm-ar that's distro'd as part of the android NDK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants