title: CMake, Android NDK toolchain on Windows
body: <p>I know about <code>android-cmake</code>, but first I'm starting simple to understand how everything fits together.</p>
  
  <p>I make sure <code>&lt;ndk&gt;\prebuilt\windows-x86_64\bin</code> is in my path (this is where make lives), and I make sure <code>&lt;ndk&gt;\toolchains\x86-4.9\prebuilt\windows-x86_64\bin</code> is in my path (this is where g++ lives). Then I <code>set CC=i686-linux-android-gcc</code> and <code>CXX=i686-linux-android-g++</code>. Everything seems so far so good; cmake can identify both make and the compilers, but it fails when it checks that the C compiler is working, and I can't make sense of the error message to understand what went wrong.</p>
  
  <p>Here's the cmake output:</p>
  
  <pre><code>C:\test_project\build&gt;cmake -G "Unix Makefiles" ..
  
  -- The C compiler identification is GNU 4.9.0
  -- The CXX compiler identification is GNU 4.9.0
  -- Check for working C compiler: C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/i686-linux-android-gcc.exe
  -- Check for working C compiler: C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/i686-linux-android-gcc.exe -- broken
  CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.1/Modules/CMakeTestCCompiler.cmake:61 (message):
    The C compiler
    "C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/i686-linux-android-gcc.exe"
    is not able to compile a simple test program.
  
    It fails with the following output:
  
     Change Dir: C:/test_project/build/CMakeFiles/CMakeTmp
  
  
  
    Run Build
    Command:"C:/android-ndk-r10d-windows-x86_64/prebuilt/windows-x86_64/bin/make.exe"
    "cmTryCompileExec924087958/fast"
  
  
    C:/android-ndk-r10d-windows-x86_64/prebuilt/windows-x86_64/bin/make.exe
    -f CMakeFiles/cmTryCompileExec924087958.dir/build.make
    CMakeFiles/cmTryCompileExec924087958.dir/build
  
    make.exe[1]: Entering directory
    `C:/test_project/build/CMakeFiles/CMakeTmp'
  
    "C:/Program Files (x86)/CMake/bin/cmake.exe" -E cmake_progress_report
    C:/test_project/build/CMakeFiles/CMakeTmp/CMakeFiles
    1
  
    "Building C object
    CMakeFiles/cmTryCompileExec924087958.dir/testCCompiler.c.obj"
  
  
    C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/i686-linux-android-gcc.exe
    -o CMakeFiles/cmTryCompileExec924087958.dir/testCCompiler.c.obj -c
    C:/test_project/build/CMakeFiles/CMakeTmp/testCCompiler.c
  
  
    "Linking C executable cmTryCompileExec924087958.exe"
  
    "C:/Program Files (x86)/CMake/bin/cmake.exe" -E remove -f
    CMakeFiles/cmTryCompileExec924087958.dir/objects.a
  
    CMAKE_AR-NOTFOUND cr CMakeFiles/cmTryCompileExec924087958.dir/objects.a
    @CMakeFiles/cmTryCompileExec924087958.dir/objects1.rsp
  
    process_begin: CreateProcess(NULL, CMAKE_AR-NOTFOUND cr
    CMakeFiles/cmTryCompileExec924087958.dir/objects.a
    @CMakeFiles/cmTryCompileExec924087958.dir/objects1.rsp, ...) failed.
  
    make (e=2): The system cannot find the file specified.
  
    make.exe[1]: *** [cmTryCompileExec924087958.exe] Error 2
  
    make.exe[1]: Leaving directory
    `C:/test_project/build/CMakeFiles/CMakeTmp'
  
    make.exe: *** [cmTryCompileExec924087958/fast] Error 2
  
  
  
  
  
    CMake will not be able to correctly generate this project.
  Call Stack (most recent call first):
    CMakeLists.txt:1 (project)
  
  
  -- Configuring incomplete, errors occurred!
  See also "C:/test_project/build/CMakeFiles/CMakeOutput.log".
  See also "C:/test_project/build/CMakeFiles/CMakeError.log".
  
  C:\test_project\build&gt;
  </code></pre>
  
  <p>And here's the error log:</p>
  
  <pre><code>Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
  Compiler: C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/i686-linux-android-gcc.exe 
  Build flags: 
  Id flags: 
  
  The output was:
  1
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot open crtbegin_dynamic.o: No such file or directory
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot open crtend_android.o: No such file or directory
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot find -lc
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot find -ldl
  collect2.exe: error: ld returned 1 exit status
  
  
  Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
  Compiler: C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/i686-linux-android-g++.exe 
  Build flags: 
  Id flags: 
  
  The output was:
  1
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot open crtbegin_dynamic.o: No such file or directory
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot open crtend_android.o: No such file or directory
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot find -lstdc++
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot find -lm
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot find -lc
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot find -ldl
  collect2.exe: error: ld returned 1 exit status
  
  
  Determining if the C compiler works failed with the following output:
  Change Dir: C:/test_project/build/CMakeFiles/CMakeTmp
  
  Run Build Command:"C:/android-ndk-r10d-windows-x86_64/prebuilt/windows-x86_64/bin/make.exe" "cmTryCompileExec924087958/fast"
  C:/android-ndk-r10d-windows-x86_64/prebuilt/windows-x86_64/bin/make.exe -f CMakeFiles/cmTryCompileExec924087958.dir/build.make CMakeFiles/cmTryCompileExec924087958.dir/build
  
  make.exe[1]: Entering directory `C:/test_project/build/CMakeFiles/CMakeTmp'
  
  "C:/Program Files (x86)/CMake/bin/cmake.exe" -E cmake_progress_report C:/test_project/build/CMakeFiles/CMakeTmp/CMakeFiles 1
  
  "Building C object CMakeFiles/cmTryCompileExec924087958.dir/testCCompiler.c.obj"
  
  C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/i686-linux-android-gcc.exe    -o CMakeFiles/cmTryCompileExec924087958.dir/testCCompiler.c.obj   -c C:/test_project/build/CMakeFiles/CMakeTmp/testCCompiler.c
  
  "Linking C executable cmTryCompileExec924087958.exe"
  
  "C:/Program Files (x86)/CMake/bin/cmake.exe" -E remove -f CMakeFiles/cmTryCompileExec924087958.dir/objects.a
  
  CMAKE_AR-NOTFOUND cr CMakeFiles/cmTryCompileExec924087958.dir/objects.a @CMakeFiles/cmTryCompileExec924087958.dir/objects1.rsp
  
  process_begin: CreateProcess(NULL, CMAKE_AR-NOTFOUND cr CMakeFiles/cmTryCompileExec924087958.dir/objects.a @CMakeFiles/cmTryCompileExec924087958.dir/objects1.rsp, ...) failed.
  
  make (e=2): The system cannot find the file specified.
  
  
  make.exe[1]: *** [cmTryCompileExec924087958.exe] Error 2
  
  make.exe[1]: Leaving directory `C:/test_project/build/CMakeFiles/CMakeTmp'
  
  make.exe: *** [cmTryCompileExec924087958/fast] Error 2
  </code></pre>
  
  <p>Thoughts?</p>
  
  <p>EDIT: Tsyvarev's comment fixed this problem, and cmake can find <code>ar</code> now. But sadly that only revealed the next error, which seems to be a bad option to the linker? I'm not sure why it happens or the best way to fix it.</p>
  
  <p>Cmake output:</p>
  
  <pre><code>C:\test_project\build&gt;cmake -G "Unix Makefiles" ..
  
  -- The C compiler identification is GNU 4.9.0
  -- The CXX compiler identification is GNU 4.9.0
  -- Check for working C compiler: C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/gcc.exe
  -- Check for working C compiler: C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/gcc.exe -- broken
  CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.1/Modules/CMakeTestCCompiler.cmake:61 (message):
    The C compiler
    "C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/gcc.exe"
    is not able to compile a simple test program.
  
    It fails with the following output:
  
     Change Dir: C:/test_project/build/CMakeFiles/CMakeTmp
  
  
  
    Run Build
    Command:"C:/android-ndk-r10d-windows-x86_64/prebuilt/windows-x86_64/bin/make.exe"
    "cmTryCompileExec2113787949/fast"
  
  
    C:/android-ndk-r10d-windows-x86_64/prebuilt/windows-x86_64/bin/make.exe
    -f CMakeFiles/cmTryCompileExec2113787949.dir/build.make
    CMakeFiles/cmTryCompileExec2113787949.dir/build
  
    make.exe[1]: Entering directory
    `C:/test_project/build/CMakeFiles/CMakeTmp'
  
    "C:/Program Files (x86)/CMake/bin/cmake.exe" -E cmake_progress_report
    C:/test_project/build/CMakeFiles/CMakeTmp/CMakeFiles
    1
  
    "Building C object
    CMakeFiles/cmTryCompileExec2113787949.dir/testCCompiler.c.obj"
  
  
    C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/gcc.exe
    -o CMakeFiles/cmTryCompileExec2113787949.dir/testCCompiler.c.obj -c
    C:/test_project/build/CMakeFiles/CMakeTmp/testCCompiler.c
  
  
    "Linking C executable cmTryCompileExec2113787949.exe"
  
    "C:/Program Files (x86)/CMake/bin/cmake.exe" -E remove -f
    CMakeFiles/cmTryCompileExec2113787949.dir/objects.a
  
  
    C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/ar.exe
    cr CMakeFiles/cmTryCompileExec2113787949.dir/objects.a
    @CMakeFiles/cmTryCompileExec2113787949.dir/objects1.rsp
  
  
    C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/gcc.exe
    -Wl,--whole-archive CMakeFiles/cmTryCompileExec2113787949.dir/objects.a
    -Wl,--no-whole-archive -o cmTryCompileExec2113787949.exe
    -Wl,--out-implib,libcmTryCompileExec2113787949.dll.a
    -Wl,--major-image-version,0,--minor-image-version,0
  
  
    c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe:
    --out-implib: unknown option
  
  
    c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe:
    use the --help option for usage information
  
    collect2.exe: error: ld returned 1 exit status
  
    make.exe[1]: *** [cmTryCompileExec2113787949.exe] Error 1
  
    make.exe[1]: Leaving directory
    `C:/test_project/build/CMakeFiles/CMakeTmp'
  
    make.exe: *** [cmTryCompileExec2113787949/fast] Error 2
  
  
  
  
  
    CMake will not be able to correctly generate this project.
  Call Stack (most recent call first):
    CMakeLists.txt:1 (project)
  
  
  -- Configuring incomplete, errors occurred!
  See also "C:/test_project/build/CMakeFiles/CMakeOutput.log".
  See also "C:/test_project/build/CMakeFiles/CMakeError.log".
  </code></pre>
  
  <p>Error log:</p>
  
  <pre><code>Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
  Compiler: C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/gcc.exe 
  Build flags: 
  Id flags: 
  
  The output was:
  1
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot open crtbegin_dynamic.o: No such file or directory
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot open crtend_android.o: No such file or directory
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot find -lc
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot find -ldl
  collect2.exe: error: ld returned 1 exit status
  
  
  Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
  Compiler: C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/c++.exe 
  Build flags: 
  Id flags: 
  
  The output was:
  1
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot open crtbegin_dynamic.o: No such file or directory
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot open crtend_android.o: No such file or directory
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot find -lstdc++
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot find -lm
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot find -lc
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: error: cannot find -ldl
  collect2.exe: error: ld returned 1 exit status
  
  
  Determining if the C compiler works failed with the following output:
  Change Dir: C:/test_project/build/CMakeFiles/CMakeTmp
  
  Run Build Command:"C:/android-ndk-r10d-windows-x86_64/prebuilt/windows-x86_64/bin/make.exe" "cmTryCompileExec3892407508/fast"
  C:/android-ndk-r10d-windows-x86_64/prebuilt/windows-x86_64/bin/make.exe -f CMakeFiles/cmTryCompileExec3892407508.dir/build.make CMakeFiles/cmTryCompileExec3892407508.dir/build
  
  make.exe[1]: Entering directory `C:/test_project/build/CMakeFiles/CMakeTmp'
  
  "C:/Program Files (x86)/CMake/bin/cmake.exe" -E cmake_progress_report C:/test_project/build/CMakeFiles/CMakeTmp/CMakeFiles 1
  
  "Building C object CMakeFiles/cmTryCompileExec3892407508.dir/testCCompiler.c.obj"
  
  C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/gcc.exe    -o CMakeFiles/cmTryCompileExec3892407508.dir/testCCompiler.c.obj   -c C:/test_project/build/CMakeFiles/CMakeTmp/testCCompiler.c
  
  "Linking C executable cmTryCompileExec3892407508.exe"
  
  "C:/Program Files (x86)/CMake/bin/cmake.exe" -E remove -f CMakeFiles/cmTryCompileExec3892407508.dir/objects.a
  
  C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/ar.exe cr CMakeFiles/cmTryCompileExec3892407508.dir/objects.a @CMakeFiles/cmTryCompileExec3892407508.dir/objects1.rsp
  
  C:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/gcc.exe      -Wl,--whole-archive CMakeFiles/cmTryCompileExec3892407508.dir/objects.a -Wl,--no-whole-archive  -o cmTryCompileExec3892407508.exe -Wl,--out-implib,libcmTryCompileExec3892407508.dll.a -Wl,--major-image-version,0,--minor-image-version,0  
  
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: --out-implib: unknown option
  
  c:/android-ndk-r10d-windows-x86_64/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld.exe: use the --help option for usage information
  
  collect2.exe: error: ld returned 1 exit status
  
  make.exe[1]: *** [cmTryCompileExec3892407508.exe] Error 1
  
  make.exe[1]: Leaving directory `C:/test_project/build/CMakeFiles/CMakeTmp'
  
  make.exe: *** [cmTryCompileExec3892407508/fast] Error 2
  </code></pre>