简体   繁体   中英

Cross-compiling Freetype 2.5.3 for Android

I'm trying to cross-compile Freetype 2.5.3, so I could use it with my Android NDK Opengl ES 2 project, but I'm not sure how to do it. I'm using Cygwin on Windows. I already searched and read a lot of stuff about it, but I still need help.

I exported some flags in cygwin:

$ export NDK_TOOLCHAIN=/cygdrive/d/Development/Android/ndk-standalone-15
$ export PATH="$NDK_TOOLCHAIN/bin/:$PATH"
$ export HOST=arm-linux-androideabi
$ export CC=$HOST-gcc
$ export CXX=$HOST-g++
$ export AR=$HOST-ar
$ export LD=$HOST-ld
$ export AS=$HOST-as
$ export NM=$HOST-nm
$ export STRIP=$HOST-strip
$ export RANLIB=$HOST-ranlib
$ export OBJDUMP=$HOST-objdump
$ export CPPFLAGS="--sysroot=$NDK_TOOLCHAIN/sysroot -I$NDK_TOOLCHAIN/sysroot/usr/include -I$NDK_TOOLCHAIN/include"
$ export LDFLAGS="-L$NDK_TOOLCHAIN/sysroot/usr/lib -L$NDK_TOOLCHAIN/lib"

And then I tried to cross-compile freetype:

$ ./configure --with-sysroot=/cygdrive/d/Development/Android/ndk-standalone-15/sysroot --host=$HOST --prefix=/ft2tmp --build=$BUILD --without-zlib --with-png=no

But I got an error:

FreeType build system -- automatic system detection

The following settings are used:

platform unix compiler
arm-linux-androideabi-gcc configuration directory ./builds/unix configuration rules ./builds/unix/unix.mk

If this does not correspond to your system or settings please remove the file `config.mk' from this directory then read the INSTALL file for help.

Otherwise, simply type make' again to build the library, or make refdoc' to build the API reference (the latter needs python).

cd builds/unix; /bin/sh ./configure '--with-sysroot=/cygdrive/d/Development/Android/ndk-standalone-15/sysroot' '--host=arm-linux-androideabi' '--prefix=/ft2tmp' '--build=' '--without-zlib' '--with-png=no' checking build system type... x86_64-unknown-cygwin checking host system type... arm-unknown-linux-androideabi checking for arm-linux-androideabi-gcc... arm-linux-androideabi-gcc checking whether the C compiler works... no configure: error: in /cygdrive/d/Development/tmp/freetype2/builds/unix': configure: error: C compiler cannot create executables See config.log' for more details builds/unix/detect.mk:86: recipe for target 'setup' failed make: * [setup] Error 77

Some of the config.log file:

gcc version 4.8 (GCC) configure:2925: $? = 0 configure:2914: arm-linux-androideabi-gcc -V >&5 arm-linux-androideabi-gcc.exe: error: unrecognized command line option '-V' arm-linux-androideabi-gcc.exe: fatal error: no input files compilation terminated. configure:2925: $? = 1 configure:2914: arm-linux-androideabi-gcc -qversion >&5 arm-linux-androideabi-gcc.exe: error: unrecognized command line option '-qversion' arm-linux-androideabi-gcc.exe: fatal error: no input files compilation terminated. configure:2925: $? = 1 configure:2945: checking whether the C compiler works configure:2967: arm-linux-androideabi-gcc --sysroot=/cygdrive/d/Development/Android/ndk-standalone-15//sysroot -I/cygdrive/d/Development/Android/ndk-standalone-15//sysroot/usr/include -I/cygdrive/d/Development/Android/ndk-standalone-15//include -L/cygdrive/d/Development/Android/ndk-standalone-15//sysroot/usr/lib -L/cygdrive/d/Development/Android/ndk-standalone-15//lib conftest.c >&5 d:/development/android/ndk-standalone-15/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot open crtbegin_dynamic.o: No such file or directory d:/development/android/ndk-standalone-15/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot open crtend_android.o: No such file or directory d:/development/android/ndk-standalone-15/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot find -lc d:/development/androi d/ndk-standalone-15/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot find -ldl collect2.exe: error: ld returned 1 exit status configure:2971: $? = 1 configure:3009: result: no configure: failed

So my question is how should I do this properly?

EDIT:

I used unset on CPPFLAGS and LDFLAGS and used ./configure with --with-sysroot flag, and now it's doing okay. Next problem is that when I use

make

I get the following error:

$ make ./builds/unix/libtool --mode=compile arm-linux-androideabi-gcc -pedantic -ansi -I/cygdrive/d/Development/tmp/freetype2/objs -I./builds/unix -I/cygdrive/d/Development/tmp/freetype2/include -c -Wall -g -O2 -DFT_CONFIG_OPTION_SYSTEM_ZLIB -DFT_CONFIG_CONFIG_H="" -DFT2_BUILD_LIBRARY -DFT_CONFIG_MODULES_H="" -o /cygdrive/d/Development/tmp/freetype2/objs/ftsystem.lo /cygdrive/d/Development/tmp/freetype2/src/base/ftsystem.c libtool: compile: arm-linux-androideabi-gcc -pedantic -ansi -I/cygdrive/d/Development/tmp/freetype2/objs -I./builds/unix -I/cygdrive/d/Development/tmp/freetype2/include -c -Wall -g -O2 -DFT_CONFIG_OPTION_SYSTEM_ZLIB "-DFT_CONFIG_CONFIG_H=" -DFT2_BUILD_LIBRARY "-DFT_CONFIG_MODULES_H=" /cygdrive/d/Development/tmp/freetype2/src/base/ftsystem.c -fPIC -DPIC -o /cygdrive/d/Development/tmp/freetype2/objs/.libs/ftsystem.o arm-linux-androideabi-gcc.exe: error: /cygdrive/d/Development/tmp/freetype2/src/base/ftsystem.c: No such file or directory arm-linux-androideabi-gcc.exe: f atal error: no input files compilation terminated. /cygdrive/d/Development/tmp/freetype2/builds/freetype.mk:207: recipe for target '/cygdrive/d/Development/tmp/freetype2/objs/ftsystem.lo' failed make: * [/cygdrive/d/Development/tmp/freetype2/objs/ftsystem.lo] Error 1

You have to set the Windows-style path providing where freetype2 is located. Here is how to include in your windows environment path the libraries and files that you are using for your development in Android . The same thing you need to do for the freetype2 .

You may find useful to check these references:

As you will probably observe, most of the best material available to develop Android Apps are on Linux:

在此输入图像描述

In case you are really serious about Android development, it would be worth to consider moving your development to a Linux platform.

You should also have a look on the OpenGL Getting Started , that provides several tutorials on how work with OpenGL on Linux , Windows and MacOS. Taking a gentle step by step approach is more productive to successfully grow your OpenGL development skills.

When it comes to cross compilation of library which are written in C we require NDK. But Compiling such type of Library on windows is very difficult and sometimes stuck. I advise you to try the compilation on Linux. It will definitely be compiled

NDK for Windows does not depend on Cygwin, and worse: it does not recognize /cygdrive/... paths. Try to use D:/Development/tmp/freetype2 .

First, prepare a standalone NDK toolchain. See https://stackoverflow.com/a/24978903/192373 . I used the following parameters:

bash-3.1$ d:/dev/Android/ndk/build/tools/make-standalone-toolchain.sh --platform=android-14 --toolchain=arm-linux-androideabi-4.8 --system=windows-x86_64 --arch=armv7a

Next, make sure that you have working /usr/bin/gcc .

bash-3.1$ ./configure --host=arm-linux-androideabi --prefix=d:/Dev/Android/standalone-toolchain-armv7a-android-17 --without-zlib --with-png=no

Finally, I run make and I see

 Directory of d:\dev\freetype-2.5.3\objs\.libs

27/07/2014  10:43         3,462,596 libfreetype.a
27/07/2014  10:43               960 libfreetype.la
27/07/2014  10:43               961 libfreetype.lai
27/07/2014  10:43         2,320,272 libfreetype.so

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM