How to build GLib for iOS - ios

I want to use lasem in my iOS App, but compiling lasem needs glib. How to build it?
I download glib-2.37.4 from https://git.gnome.org/browse/glib/refs/tags. I then used autogen.sh to get a configure file, ran make and installed on mac. I wrote a shell script try to build glib for iOS, as blow:
export path=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/bin/:$path
export CC=arm-apple-darwin10-llvm-gcc-4.2
export CFLAGS="-arch armv7"
export LDFLAGS="-miphoneos-version-min=2.0"
export LD="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ld--disable-cxx"
./configure --prefix=/usr/local/ios/ --host=arm-apple-darwin10 --enable-static=yes --enable-shared=no CC=$CC CFLAGS=$CFLAGS CPP=cpp AR=ar LDFLAGS=$LDFLAGS LD=$LD
When I run this script, return as:
checking for arm-apple-darwin10-gcc... arm-apple-darwin10-llvm-gcc-4.2
checking whether the C compiler works... no
configure: error: in `/Users/tinyfool/Downloads/glib-2.34.3':
configure: error: C compiler cannot create executables
What can I do?

Given that you have built libffi and proxy-libintl for iOS, and installed both those to the same PREFIX as this script uses, this will build GLib for you:
#! /bin/bash
export MINVER="5.1" # the minimum supported OS version
export SDKVER="5.1" # SDK version
export PREFIX="$HOME/built-for-ios" # where the library goes
export DEVROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer"
export SDKROOT="${DEVROOT}/SDKs/iPhoneOS${SDKVER}.sdk"
export PKG_CONFIG_LIBDIR="${PREFIX}/lib/pkgconfig:${SDKROOT}/usr/lib/pkgconfig"
export COMMON_FLAGS="-arch armv7 -isysroot ${SDKROOT}"
export CPPFLAGS="-I${PREFIX}/include ${COMMON_FLAGS} -miphoneos-version-min=${MINVER}"
export CFLAGS="${CPPFLAGS}"
export LDFLAGS="-L${PREFIX}/lib ${COMMON_FLAGS} -Wl,-iphoneos_version_min,${MINVER}"
export CC="${DEVROOT}/usr/bin/gcc"
export CXX="${DEVROOT}/usr/bin/g++"
export OBJC="${CC}"
export LD="${CC}"
[ ! -d "${PREFIX}" ] && mkdir -p "${PREFIX}"
./configure --prefix="${PREFIX}" \
--build="x86_64-apple-darwin" \
--host="arm-apple-darwin" \
--enable-static \
--disable-shared \
glib_cv_stack_grows=no \
glib_cv_uscore=no \
ac_cv_func_posix_getgrgid_r=yes \
ac_cv_func_posix_getpwuid_r=yes

Related

How to cross-compile Coreutils or other GNU projects with clang/LLVM?

I have a tough need to compile Coreutils with llvm for other arch: arm/aarch64/mips/mips32/ppc/ppc32...
Since I install all the gcc-cross tools like mips-linux-gnu, powerpc64-linux-gnu and if I have a simple C program like that test.c
#include<stdio.h>
int main(){
printf("hello!");
return 0;
}
I can compile it to the arch, i.e.
clang --target=mips64-linux-gnuabi64 test.c -o test-mips64
➜ tests file test-mips64
test-mips64: ELF 64-bit MSB executable, MIPS, MIPS64 rel2 version 1 (SYSV), dynamically linked, interpreter /lib64/ld.so.1, BuildID[sha1]=7b33d55a0d08e6cd18d966341590dc351e346a78, for GNU/Linux 3.2.0, not stripped
I try to the same way for compile Coreutils that try to set
export CC=clang
export CXX=clang++
CFLAGS = "--target=mips64-linux-gnuabi64"
./configure --host=mips64-linux-gnuabi64
Howerver, every time got errors in configure or make...
How should I set the configure? Can I easily compile Coreuntils with llvm for other archs?
It's a bit tricky to get the command-line options right for cross-compiling. I got it to work with the commands below, assuming you're working on a Debian-based system (like Debian or Ubuntu). Here are the steps.
Install gcc-mips64-linux-gnuabi64 and gcc-powerpc64-linux-gnu.
Choose the correct arguments for CFLAGS
-B/usr/mips64-linux-gnuabi64/bin/ to indicate we want to use the linker ld within that directory. Do the same for powerpc.
--target=mips64-linux-gnuabi64 to indicate what our target for compilation is. Do the same for powerpc.
-I/usr/mips64-linux-gnuabi64/include to include header files. Do the same for powerpc.
Use ./configure --host=mips64-linux-gnuabi to configure for mips64 and ./configure --host=powerpc64-linux-gnueabi to configure for powerpc64.
Here are the commands to compile for mips64:
make clean
CFLAGS="-B/usr/mips64-linux-gnuabi64/bin/ --target=mips64-linux-gnuabi64 -I/usr/mips64-linux-gnuabi64/include" \
./configure --host=mips64-linux-gnuabi
make
And the commands to compile for powerpc64:
make clean
CFLAGS="-B/usr/powerpc64-linux-gnu/bin/ --target=powerpc64-linux-gnueabi -I/usr/powerpc64-linux-gnu/include" \
./configure --host=powerpc64-linux-gnueabi
make
Here is the output of file ./src/ls to demonstrate that it is a powerpc64 executable:
$ file ./src/ls
./src/ls: ELF 64-bit MSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), dynamically linked, interpreter /lib64/ld64.so.1, for GNU/Linux 3.2.0, BuildID[sha1]=97fe33981ca0112160f44a6fb678d6dc1b462114, not stripped
Below is a Dockerfile that can be used to reproducibly cross-compile coreutils for mips64 and powerpc64.
# Cross-compile GNU coreutils for mips64 and powerpc64 using clang.
# With help from https://medium.com/#wolfv/cross-compiling-arm-on-travis-using-clang-and-qemu-2b9702d7c6f3
FROM debian:buster
# Install compile-time dependencies.
RUN apt-get update \
&& apt-get install --yes \
clang \
curl \
gcc-mips64-linux-gnuabi64 \
gcc-powerpc64-linux-gnu \
make \
perl \
&& rm -rf /var/lib/apt/lists/*
# Download source code for release.
WORKDIR /tmp/coreutils
RUN curl -fsSL https://ftp.gnu.org/gnu/coreutils/coreutils-8.32.tar.xz \
| tar xJ --strip-components 1
# Compile and install for mips64.
RUN CFLAGS="-B/usr/mips64-linux-gnuabi64/bin/ --target=mips64-linux-gnuabi64 -I/usr/mips64-linux-gnuabi64/include" \
./configure --host=mips64-linux-gnuabi --prefix=/opt/coreutils-mips \
&& make \
&& make install
# Compile and install for powerpc64.
RUN make clean \
&& CFLAGS="-B/usr/powerpc64-linux-gnu/bin/ --target=powerpc64-linux-gnueabi -I/usr/powerpc64-linux-gnu/include" \
./configure --host=powerpc64-linux-gnueabi --prefix=/opt/coreutils-powerpc64 \
&& make \
&& make install
# Keep only the compiled programs from the previous stage.
FROM debian:buster
COPY --from=0 /opt /opt
I am current working on a simple build tool in Python that maybe help you.
Unfortunately, still at moment, lacks clang implementation, but works fine with GCC and MSVC.
Basically the thing mix Json parameters files to generate command line building.
CppMagic

Cross-compiling on Linux for iOS

I am trying to cross-compile Ruby for iOS devices. I have a rather lengthy script that downloads the latest source code for Ruby, unzips it, and compiles it.
The script is as follows:
#!/bin/bash
rm -rf ~/built/ruby
AR=~/toolchain/armv7-apple-darwin11-ar
AS=~/toolchain/armv7-apple-darwin11-as
CC=~/toolchain/armv7-apple-darwin11-clang
CXX=~/toolchain/armv7-apple-darwin11-clang++
LD=~/toolchain/armv7-apple-darwin11-ld
NM=~/toolchain/armv7-apple-darwin11-nm
OBJDUMP=~/toolchain/armv7-apple-darwin11-objdump
RANLIB=~/toolchain/armv7-apple-darwin11-ranlib
STRIP=~/toolchain/armv7-apple-darwin11-strip
SDK=/home/citrusui/sdks/iPhoneOS9.3.sdk
CFLAGS="-arch armv7 -arch arm64 -isysroot $SDK"
LDFLAGS="-Wl,-segalign,4000"
DESTDIR=~/built/ruby/var/stash
apt install autoconf bison clang jq xutils-dev
curl https://api.github.com/repos/ruby/ruby/tags -o ruby.json
URL=`jq -r 'map(select(.name != "yarv_migration_base"))[0].tarball_url' ruby.json`
TAG=`jq -r 'map(select(.name != "yarv_migration_base"))[0].name' ruby.json`
echo "Downloading from $URL"...
if [ -f ruby_$TAG.tar.gz ] && [ -d ruby-ruby* ]; then
echo "Already downloaded."
cd ruby-ruby*
autoconf
./configure --host=armv7-apple-darwin11 -target=armv7-apple-darwin11 CC="$CC" CXX="$CXX" CXXFLAGS="$CFLAGS" CFLAGS="$CFLAGS" STRIP=$STRIP RANLIB=$RANLIB NM=$NM AR=$AR AS=$AS LD=$LD OBJDUMP=$OBJDUMP LDFLAGS="$LDFLAGS" DESTDIR="$DESTDIR"
make install -j4
cd ~/built/ruby
lndir var/stash
exit 0
fi
curl -L $URL -o ruby_$TAG.tar.gz
tar -xvzf ruby_$TAG.tar.gz
cd ruby-ruby*
autoconf
./configure --host=armv7-apple-darwin11 -target=armv7-apple-darwin11 CC="$CC" CXX="$CXX" CXXFLAGS="$CFLAGS" CFLAGS="$CFLAGS" STRIP=$STRIP RANLIB=$RANLIB NM=$NM AR=$AR AS=$AS LD=$LD OBJDUMP=$OBJDUMP LDFLAGS="$LDFLAGS" DESTDIR="$DESTDIR"
make install -j4
cd ~/built/ruby
lndir var/stash
Now, I have also downloaded the iOS 9.3 SDK from Xcode and dropped it into my ~/sdks/ folder. However, the compiling process still results in ELF format binaries.
I also have a toolchain (in ~/toolchain/) downloaded from here. I assume this will allow LLVM/Clang to produce arm(64) binaries, but I don't know how I would tell clang to process this toolchain. Specifying $TOOLCHAIN in ./configure doesn't help, either.

Can't compile CUDA samples: ld: library not found for -lgomp clang: error: linker command failed with exit code 1 [duplicate]

I'm trying to get openmp to run in my program on Mavericks, however when I try to compile using the flag -fopenmp I get the following error:
ld: library not found for -lgomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The command I am running is:
gcc myProgram.cpp -fopenmp -o myProgram
Also, when I run gcc I get Clang warnings which I find to be very strange. And looking into /usr/bin/gcc it does not appear to link to Clang.
Any suggestions on how to fix my Clang errors and get openmp to compile?
The gcc command in the latest Xcode suite is no longer the GCC frontend to LLVM (based on the very old GCC 4.2.1) but rather a symlink to clang. Clang does not (yet) support OpenMP. You have to install separately another version of GCC, e.g. by following this tutorial or by using any of the available software package management systems like MacPorts and Homebrew.
I just recently attacked this problem and have scripted the process of getting everything working based on the official instructions.
The script will download everything into ~/code for easy maintenance and will append the correct environment variables to your ~/.profile file. For advanced users, pick a nice location you want the lib, bin and include installed and move them manually. The script depends on knowing the latest OpenMP runtime from Intel, which can be altered at the top of the script.
The script should work out of the box with vanilla Mavericks, except for one small problem. In the OpenML runtime make script, it does not reliably accept clang when specified and continues with the default GCC. As such, if you don't have GCC installed (which is not normal on out of the box Mavericks), it will fail to build. To fix this, you must comment out two lines (as noted in the script) based on the libomp_20131209_oss.tgz build of OpenMP. Newer builds of OpenML might break this script, so use at your own peril on newer versions.
Simply save this script into a file, run 'chmod +x filename.sh', and run './filename.sh' from terminal. It will take a while to build LLVM and Clang, so be patient.
EDIT: This script will most likely fail on Yosemite and I am having issues using the built clang2 after the update to the dev builds of OSX 10.10.
INTEL_OPENMP_LATEST_BUILD_LINK=https://www.openmprtl.org/sites/default/files/libomp_20131209_oss.tgz
DEST_FOLDER = ~/code
CLANG_INCLUDE=${DEST_FOLDER}/llvm/include
CLANG_BIN=${DEST_FOLDER}/llvm/build/Debug+Asserts/bin
CLANG_LIB=${DEST_FOLDER}/llvm/build/Debug+Asserts/lib
OPENMP_INCLUDE=${DEST_FOLDER}/libomp_oss/exports/common/include
OPENMP_LIB=${DEST_FOLDER}/libomp_oss/exports/mac_32e/lib.thin
mkdir ${DEST_FOLDER}
cd ${DEST_FOLDER}
git clone https://github.com/clang-omp/llvm
git clone https://github.com/clang-omp/compiler-rt llvm/projects/compiler-rt
git clone -b clang-omp https://github.com/clang-omp/clang llvm/tools/clang
cd llvm
mkdir build
cd build
../configure
make
cd Debug+Asserts/bin
mv clang clang2
rm -rf clang++
ln -s clang2 clang2++
echo "LLVM+Clang+OpenMP Include Path : " ${CLANG_INCLUDE}
echo "LLVM+Clang+OpenMP Bin Path : " ${CLANG_BIN}
echo "LLVM+Clang+OpenMP Lib Path : " ${CLANG_LIB}
cd ${DEST_FOLDER}
curl ${INTEL_OPENMP_LATEST_BUILD_LINK} -o libomp_oss_temp.tgz
gunzip -c libomp_oss_temp.tgz | tar xopf -
rm -rf libomp_oss_temp.tgz
cd libomp_oss
echo "You need to do one or two things:"
echo "1.) [Required] Comment out line 433 from libomp_oss/src/makefile.mk"
echo "2.) [Optional] If you do not have GCC installed (not normal on vanilla Mavericks), you must comment out lines 450-451 in libomp_oss/tools/check-tools.pl. Have you done this or want to compile anyway?"
select yn in "Yes" "No"; do
case $yn in
Yes ) make compiler=clang; break;;
No ) exit;;
esac
done
echo "OpenMP Runtime Include Path : " ${OPENMP_INCLUDE}
echo "OpenMP Runtime Lib Path : " ${OPENMP_LIB}
(echo 'export PATH='${CLANG_BIN}':$PATH';
echo 'export C_INCLUDE_PATH='${CLANG_INCLUDE}':'${OPENMP_INCLUDE}':$C_INCLUDE_PATH';
echo 'export CPLUS_INCLUDE_PATH='${CLANG_INCLUDE}':'${OPENMP_INCLUDE}':$CPLUS_INCLUDE_PATH';
echo 'export LIBRARY_PATH='${CLANG_LIB}':'${OPENMP_LIB}':$LIBRARY_PATH';
echo 'export DYLD_LIBRARY_PATH='${CLANG_LIB}':'${OPENMP_LIB}':$DYLD_LIBRARY_PATH}') >> ~/.profile
source ~/.profile
echo "LLVM+Clang+OpenMP is now accessible through [ clang2 ] via terminal and does not conflict with Apple's clang"
If you are running homebrew you can fix this problem by calling:
brew install clang-omp
The compiler will be available under clang-omp++ name
Just worked through this problem. Here's the answer plus how to get it worked with Xcode.
Grab the latest version of openMP runtime library from
https://www.openmprtl.org/download
unzip and compile it by
mkdir build && cd build && cmake .. && make && sudo make install
install it by
sudo cp ./libiomp5.dylib /usr/lib/
sudo cp ./omp.h /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/
Grab openmp/clang from Git following the instructions on http://clang-omp.github.io/
compile openmp/clang
cd llvm && mkdir build && cd build && ../configure --enable-optimized && make -j
sudo make install
normally it would install clang/clang++ into /usr/local/bin, we need replace the Apple clang with our version
cd /usr/bin
sudo mv clang clang-apple
sudo mv clang++ clang++-apple
sudo ln -s /usr/local/bin/clang ./clang
sudo ln -s /usr/local/bin/clang++ ./clang++
cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
sudo mv clang clang-apple
sudo mv clang++ clang++-apple
sudo ln -s /usr/local/bin/clang ./clang
sudo ln -s /usr/local/bin/clang++ ./clang++
cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
sudo mv -f * ../../
Create a project in Xcode, using the Hello World code on clang-openmp website for test. After created, add "-fopenmp" to Custom Compiler Flags -> Other C Flags in project settings; add /usr/lib/libiomp5.dylib to the build phases of project (project settings -> Build Phases -> Drag /usr/lib/libiomp5.dylib into Link Binary with Libraries)
It should work. Yosemite + Xcode 6 is tested.
Note: the custom clang is NOT as stable as Apple's. Switch back if you meet strange instruction error after compiled.

FFMPEG iOS 7 Library

I've tried reading many tutorials.
I've spent hours on google, and stackoverflow trying answer.
So far I've read: Trying to compile the FFMPEG libraries for iPhoneOS platform with armv6 and arv7 architecture FFMPEG integration on iphone/ ipad project and https://github.com/lajos/iFrameExtractor few of the many.
I'm trying to build this library for iOS 7/Xcode 5 compatibility but it's not working.
A common error I'd get is:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
yasm/nasm not found or too old. Use --disable-yasm for a crippled build.
If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user#ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "config.log" produced by configure as this will help
solving the problem.
I'd also get many more once that is finished. Such as:
rm: illegal option -- .
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
make: *** [clean] Error 64
I've mostly tried using this command to start, but it always crashes on "make clean":
./configure \
--cc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--as='/usr/local/bin/gas-preprocessor.pl /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' \
--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk \
--target-os=darwin \
--arch=arm \
--cpu=cortex-a8 \
--extra-cflags='-arch armv7' \
--extra-ldflags='-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk' \
--prefix=compiled/armv7 \
--enable-cross-compile \
--enable-nonfree \
--enable-gpl \
--disable-armv5te \
--disable-swscale-alpha \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-asm \
--disable-debug
To use the mooncatventures (our) ffmpegdecoderFramework, go into build settings
click on the arch and remove the armv7s.
you must also change build active architechure only to no.
This answer from mientus worked for me :
https://stackoverflow.com/a/19370679/661720
Support universal ffmpeg library for iOS7 and XCode5:
Install gas-preprocessor
Click on the ZIP icon to download
https://github.com/mansr/gas-preprocessor. Copy gas-preprocessor.pl to
/usr/bin directory. Change permission of gas-preprocessor.pl by
setting the privilege to Read & Write for all.
Download my shell script from: https://gist.github.com/m1entus/6983547
Run sh build-ffmpeg.sh.

Cross compiling fontconfig for iOS

How to cross compiling for fontconfig for iOS.
http://freedesktop.org/software/fontconfig/release
I try this:
./configure
CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
CFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk -arch armv7"
--sysconfdir=/Users/bluefish625/Desktop/fontconfig/sysconfdir/
--prefix=/Users/bluefish625/Desktop/fontconfig/prefix/
--mandir=/Users/bluefish625/Desktop/fontconfig/mandir
--disable-shared
--host=armv7-apple-darwin
--with-freetype-config=$PREFIX/bin/freetype-config
The error info is:
configure: error: in `/Users/bluefish625/Downloads/fontconfig-2.9.0':
configure: error: The pkg-config script could not be found or is too old.
Make sure it is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config.
Alternatively, you may set the environment variables LIBXML2_CFLAGS
and LIBXML2_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
To get pkg-config, see <http://pkg-config.freedesktop.org/>.
See `config.log' for more details
And,I don't know what this --with-freetype-config means?
can somebody help me? thanks.
Try with this:
export IOS_PLATFORMDIR="/Developer/Platforms/iPhoneOS.platform"
export IOS_SYSROOT="$IOS_PLATFORMDIR/Developer/SDKs/iPhoneOS5.0.sdk"
export IOS_GCC="$IOS_PLATFORMDIR/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2"
export IOS_CFLAGS="-march=armv6 -mcpu=arm1176jzf-s -mfpu=vfp"
./configure --host arm-apple-darwin10 --disable-docs --enable-shared=no \
--with-expat="/Users/meox/PODOFO/expat" \
--with-expat-includes="/Users/meox/PODOFO/expat/include" \
--with-expat-lib="/Users/meox/PODOFO/expat" \
CC="$IOS_GCC" LD="$IOS_GCC" \
CFLAGS="-mfloat-abi=softfp -isysroot $IOS_SYSROOT -O3 $IOS_CFLAGS" \
LDFLAGS="-mfloat-abi=softfp -isysroot $IOS_SYSROOT $IOS_CFLAGS
-L/Users/meox/PODOFO/freetype2 -L/Users/meox/PODOFO/expat
-L/Users/meox/PODOFO/zlib -L/Users/meox/PODOFO/libiconv
-L/Users/meox/PODOFO/bzip2" \
CPPFLAGS="-I/Users/meox/PODOFO/freetype2/include
-I/Users/meox/PODOFO/zlib/include -I/Users/meox/PODOFO/expat/include"
You have to set the right paths.

Resources