Armv7-linux-androideabi cross compile issues

when compiling with cargo build --target armv7-linux-androideabi it is perfectly fine, no issues what so ever, but once i compile with cargo build --target armv7-linux-androideabi --release it throws this error

error: linking with C:/android-ndk-r25c/toolchains/llvm/prebuilt/windows-x86_64/bin/armv7a-linux-androideabi22-clang.cmd failed: exit code: 255
= note: "C:/android-ndk-r25c/toolchains/llvm/prebuilt/windows-x86_64/bin/armv7a-linux-androideabi22-clang.cmd" "-march=armv7-a" "C:\Users\USERNAME\AppData\Local\Temp\rustcCNM761\symbols.o" "C:\Users\USERNAME\Desktop\wag\ib\parsatron\target\armv7-linux-androideabi\release\deps\andclip-57a6a3e6a2a039b3.andclip.9662c527-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "C:\Users\USERNAME\Desktop\wag\ib\parsatron\target\armv7-linux-androideabi\release\deps" "-L" "C:\Users\USERNAME\Desktop\wag\ib\parsatron\target\release\deps" "-L" "C:\Users\USERNAME\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\armv7-linux-androideabi\lib" "-Wl,-Bstatic" "C:\Users\USERNAME\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\armv7-linux-androideabi\lib\libcompiler_builtins-a7b4a7b4024efe3d.rlib" "-Wl,-Bdynamic" "-landroid" "-ldl" "-llog" "-lunwind" "-ldl" "-lm" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "C:\Users\USERNAME\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\armv7-linux-androideabi\lib" "-o" "C:\Users\USERNAME\Desktop\wag\ib\parsatron\target\armv7-linux-androideabi\release\deps\andclip-57a6a3e6a2a039b3" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,--strip-all" "-nodefaultlibs"
= note: =armv7-a"" was unexpected at this time.

Im still looking for help

Ive tried many different linker versions, tried cargo build, cargo ndk -t target build etc and im so confused why its having issues compiling with --release when it compiles just fine without it and when compiling for aarch64-linux-android it has no issues in debug or release mode

the command line argument is quoted, but the linker is invoked through a .cmd shim, which messed up the quotes. it's strange that the debug build actually succeeded. can you try to get the full linker command invoked when building in debug mode?

My suggestion would be invoke clang.exe directly as linker command, and passing --target=armv7a-linux-androideabi22 by cargo instead rely on the cmd shim script.


when I try to manually invoke the ndk "clang.cmd" interactively,

Z:\>rem this succeeded:
Z:\>armv7a-linux-androideabi22-clang.cmd -march=armv7-a -c empty.c

Z:\>rem this also succeeded:
Z:\>armv7a-linux-androideabi22-clang.cmd -march="armv7-a" -c empty.c

Z:\>rem but this fails:
Z:\>armv7a-linux-androideabi22-clang.cmd "-march=armv7-a" -c empty.c
=armv7-a"" was unexpected at this time.

if you check the shim script, it contains following lines:

call :find_bin
if "%1" == "-cc1" goto :L

set "_BIN_DIR=" && "%_BIN_DIR%clang.exe" --target=armv7a-linux-androideabi22 %*
if ERRORLEVEL 1 exit /b 1
goto :done

rem Accommodate a quoted arg0, e.g.: "clang"
set _BIN_DIR=%~dp0

the actual offending line is:

if "%1" == "-cc1" goto :L

because %1 is "-march=armv7-a" in this case (note it's quoted), the if command expands to:

if ""-march=armv7-a"" == "-cc1" goto :L

which, due to the obscure quoting rules of cmd, cannot be parsed correctly. in this particular case, you can workaround it by simply get rid of the quote and use an old prefix trick:

if x%1 == xcc1 goto :L

but it's not a general solution, and I'm pretty sure it will break in other situations, such as when "cc1" is passed as first agument (i.e. %1) quoted. but that's the way cmd works.


interestingly enough, in the shim script, they linked to this issue

apparently, some one else also encountered other esoteric problems related to cmd expansion and quotation rules. I wonder why they didn't write their own shim wrapper program (it's stupidly trivial, e.g. scoop use it forever) but instead used cmd all the way


Thank you so much, i spent like 8-10h troubleshooting before making this post and got nowhere but because of you and the notes you left it compiled without a issue, i love so much man for helping and if you would like a donation for helping please let me know i can throw you like $10-$15 for the help

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.