title: valgrind for Android devices (Crystax). configure: error: C compiler cannot create executables
body: <p>Using and adapting the script(<a href="https://gist.github.com/smits/27060b310546ca6f76568f24838118c3" rel="nofollow noreferrer">https://gist.github.com/smits/27060b310546ca6f76568f24838118c3</a>) I get and error " C compiler cannot create executables":</p>
  
  <pre><code>#!/usr/bin/env bash
  
  #set -x
  
  function extract()
  {
       if [ -f "$1" ] ; then
           case "$1" in
               *.tar.bz2)   tar xvjf "$1"     ;;
               *.tar.gz)    tar xvzf "$1"     ;;
               *.bz2)       bunzip2 "$1"      ;;
               *.rar)       unrar x "$1"      ;;
               *.gz)        gunzip "$1"       ;;
               *.tar)       tar xvf "$1"      ;;
               *.tbz2)      tar xvjf "$1"     ;;
               *.tgz)       tar xvzf "$1"     ;;
               *.zip)       unzip "$1"        ;;
               *.Z)         uncompress "$1"   ;;
               *.7z)        7z x "$1"         ;;
               *)           echo "$1 cannot be extracted via &gt;extract&lt;" ;;
           esac
       else
           echo "'$1' is not a valid file"
       fi
  }
  
  VALGRIND_VERSION="3.15.0"
  VALGRIND_EXTENSION=".tar.bz2"
  VALGRIND_DIRECTORY="valgrind-${VALGRIND_VERSION}"
  VALGRIND_TARBALL="valgrind-${VALGRIND_VERSION}${VALGRIND_EXTENSION}"
  
  # Only download Valgrind tarball again if not already downloaded
  if [[ ! -f "${VALGRIND_TARBALL}" ]]; then
    wget -v -nc "https://sourceware.org/pub/valgrind/${VALGRIND_TARBALL}"
  fi
  
  # Only extract Valgrind tarball again if not already extracted
  if [[ ! -d "$VALGRIND_DIRECTORY" ]]; then
    extract "$VALGRIND_TARBALL"
  fi
  
  # Ensure ANDROID_NDK is set
  #if [[ ! -z "$ANDROID_NDK" ]]; then
    export ANDROID_NDK="/home/userhome/src/crystax-ndk-10.3.1"
  #fi
  
  # Ensure ANDOID_SDK_HOME is set
  #if [[ ! -z "$ANDROID_SDK" ]]; then
    #export ANDROID_SDK="/opt/android-sdk-linux/"
  #fi
  
  if [[ ! -d "$VALGRIND_DIRECTORY" ]];
  then
    echo "Problem with extracting Valgrind from $VALGRIND_TARBALL into $VALGRIND_DIRECTORY!!!"
    exit -1
  fi
  
  # Move to extracted directory
  cd "$VALGRIND_DIRECTORY"
  
  # ARM Toolchain
  export PATH=$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin:$PATH
  ARCH_ABI="arm-linux-androideabi-6"
  export AR="$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar"
  export LD="$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld"
  export CC="$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc"
  export CXX="$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++"
  export RANLIB="$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib"
  export AS="$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-as"
  export CPP="$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-cpp"
  
  
  
  echo $ANDROID_NDK
  echo $AR
  echo $LD
  echo $CC
  echo $CXX
  
  [[ ! -d "$ANDROID_NDK" || ! -f "$AR" || ! -f "$LD" || ! -f "$CC" || ! -f "$CXX" ]] &amp;&amp; echo "Make sure AR, LD, CC, CXX variables are defined correctly. Ensure ANDROID_NDK is defined also" &amp;&amp; exit -1
  
  # Configure build
  export HWKIND="generic"
  ANDROID_PLATFORM=android-21
  export CPPFLAGS="--sysroot=$ANDROID_NDK/platforms/${ANDROID_PLATFORM}/arch-arm -DANDROID_HARDWARE_$HWKIND"
  export CFLAGS="--sysroot=$ANDROID_NDK/platforms/${ANDROID_PLATFORM}/arch-arm"
  
  # BUG: For some reason file command is unable to detect if the file does not exist with ! -f , it says it doesn't exist even when it does!!!
  BUILD=true
  if [[ "${VALGRIND_DIRECTORY}/Inst/data/local/Inst/bin/valgrind" = *"No such file or directory"* ]]; then
    BUILD=true
  fi
  
  if [[ "$BUILD" = true ]];
  then
    ./configure --prefix="/data/local/Inst" \
    --host="armv7-unknown-linux" \
    --target="armv7-unknown-linux" \
    --with-tmpdir="/sdcard"
  
    [[ $? -ne 0 ]] &amp;&amp; echo "Can't configure!" &amp;&amp; exit -1
  
    # Determine the number of jobs (commands) to be run simultaneously by GNU Make
    NO_CPU_CORES=$(grep -c ^processor /proc/cpuinfo)
  
    if [ $NO_CPU_CORES -le 8 ]; then
      JOBS=$(($NO_CPU_CORES+1))
    else
      JOBS=${NO_CPU_CORES}
    fi
  
    # Compile Valgrind 
    make -j "${JOBS}"
  
    [[ $? -ne 0 ]] &amp;&amp; echo "Can't compile!" &amp;&amp; exit -1
  
    # Install Valgrind locally
    make -j "${JOBS}" install DESTDIR="$(pwd)/Inst"
    [[ $? -ne 0 ]] &amp;&amp; echo "Can't install!" &amp;&amp; exit -1
  fi
  
  # Push local Valgrind installtion to the phone
  if [[ $(adb shell ls -ld /data/local/Inst/bin/valgrind) = *"No such file or directory"* ]];
  then
    adb root
    adb remount
    adb shell "[ ! -d /data/local/Inst ] &amp;&amp; mkdir /data/local/Inst"
    adb push Inst /
    adb shell "ls -l /data/local/Inst"
  
    # Ensure Valgrind on the phone is running
    adb shell "/data/local/Inst/bin/valgrind --version"
  
    # Add Valgrind executable to PATH (this might fail)
    adb shell "export PATH=$PATH:/data/local/Inst/bin/"
  fi
  </code></pre>
  
  <p>I got the following error ( C compiler cannot create executables):</p>
  
  <pre><code>checking for a BSD-compatible install... /usr/bin/install -c
  checking whether build environment is sane... yes
  checking for armv7-unknown-linux-strip... no
  checking for strip... strip
  checking for a thread-safe mkdir -p... /bin/mkdir -p
  checking for gawk... gawk
  checking whether make sets $(MAKE)... yes
  checking whether make supports nested variables... yes
  checking whether to enable maintainer-specific portions of Makefiles... no
  checking whether ln -s works... yes
  checking for armv7-unknown-linux-gcc... /home/rubvacalz/src/crystax-ndk-10.3.1/toolchains/arm-linux-androideabi-6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
  checking whether the C compiler works... no
  configure: error: in `/home/rubvacalz/src/valgrind-3.15.0':
  configure: error: C compiler cannot create executables
  See `config.log' for more details
  Can't configure!
  </code></pre>
  
  <p>And config.log says "error: cannot find -lcrystax":</p>
  
  <pre><code>configure:3723: checking whether the C compiler works
  configure:3745: /home/rubvacalz/src/crystax-ndk-10.3.1/toolchains/arm-linux-androideabi-6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc --sysroot=/home/rubvacalz/src/crystax-ndk-10.3.1/platforms/android-21/arch-arm --sysroot=/home/rubvacalz/src/crystax-ndk-10.3.1/platforms/android-21/arch-arm -DANDROID_HARDWARE_yellowstone  conftest.c  &gt;&amp;5
  /home/rubvacalz/src/crystax-ndk-10.3.1/toolchains/arm-linux-androideabi-6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/6.1/../../../../arm-linux-androideabi/bin/ld: **error: cannot find -lcrystax**
  collect2: error: ld returned 1 exit status
  configure:3749: $? = 1
  configure:3787: result: no
  configure: failed program was:
  </code></pre>
  
  <p>I don't know if the following includes are required and I don't know if it is included in the script process. </p>
  
  <pre><code>-I/home/userhome/src/crystax-ndk-10.3.1/sources/crystax/include -I/home/userhome/src/crystax-ndk-10.3.1/platforms/android-21/arch-arm/usr/include -I/home/userhome/src/crystax-ndk-10.3.1/sources/cxx-stl/gnu-libstdc++/6/include -I/home/userhome/src/crystax-ndk-10.3.1/sources/cxx-stl/gnu-libstdc++/6/libs/armeabi-v7a/include -I/home/userhome/src/crystax-ndk-10.3.1/sources/cxx-stl/gnu-libstdc++/6/include/backward
  </code></pre>