10

I'm trying to compile C code on a Jetson Nano and I get this error during compiling. I tried removing any occurrence of 'm -64' but it seems like its added automatically. This is the cmd where it fails: /usr/bin/gcc-7 -Wall -Wextra -Wconversion -pedantic -Wshadow -m64 -Wfatal-errors -O0 -g -o CMakeFiles/dir/testCCompiler.c.o -c /home/user/dir/CMakeFiles/CMakeTmp/testCCompiler.c

uname -a: Linux jetson-nano 4.9.140-tegra aarch64 aarch64 aarch64 GNU/Linux

gcc-7 -v: Using built-in specs.
COLLECT_GCC=gcc-7
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/7/lto-wrapper
Target: aarch64-linux-gnu
gcc version 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1)
CMAKE_C_COMPILER = gcc-7
CMAKE_CXX_COMPILER = g++-7

CXX_COMPILE_FLAGS =  "-Wall -Werror -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast -pedantic -Wshadow"
C_COMPILE_FLAGS = "-Wall -Wextra -Wconversion -pedantic -Wshadow"

gcc-7: error: unrecognized command line option ‘-m64’

Ghonima
  • 2,978
  • 2
  • 14
  • 23
Jen
  • 121
  • 1
  • 1
  • 7
  • Looks like there's more to the Makefile than you're showing here? Looks like besides `-m64` something's also adding `-Wfatal-errors -O0 -g`. Are there more Makefile rules there? – Kyrill Oct 09 '19 at 16:57

4 Answers4

10

error: unrecognized command line option ‘-m64’

I believe you are looking for -march=armv8-a (and friends), and not -m64. The GCC arm64 options are available at 3.18.1 AArch64 Options in the manual.

Aarch64 includes ASIMD in the base specification, so there are no extra gyrations needed for it. ASIMD is "Advanced SIMD instructions", and it is what ARM calls NEON on the Aarch32 and Aarch64 architectures.

If you want to enable extensions, like CRC or Crypto, then the option would look like -march=armv8.1-a+crc or -march=armv8.1-a+crypto or -march=armv8.1-a+crc+crypto.


The equivalent x86 options would be the following. Obviously, the ARM port of GCC does not use the same model as x86. It is confusing for new users (or it was confusing for me).

  • -march=armv8-a-msse2
  • -march=armv8.1-a+crc-msse2 -msse4.1
  • -march=armv8.1-a+crypto-msse2 -mpclmul -maes
  • -march=armv8.1-a+crc+crypto-msse2 -msse4.1 -mpclmul -maes

ARM instruction set includes SHA in crypto, so the x86 options should probably include -msha. The problem is, x86 SHA did not arrive until about 8 years after carryless multiplies and AES.

Also, GCC ARM compilers usually don't understand -march=native. On older GCC compilers, the compiler will just crash. On mid-ranged GCC it is simply ignored. I believe the latest GCC compilers honor it.

jww
  • 97,681
  • 90
  • 411
  • 885
  • thanks for your explanation! my problem is that i didn't put -m64 anywhere, where would I need to configure -march=armv8-a to make it work? – Jen Oct 05 '19 at 10:03
  • They are compiler options. Compiler options go in `CPPFLAGS`, `CFLAGS` and `CXXFLAGS`. I believe you would use `C_COMPILE_FLAGS` and `CXX_COMPILE_FLAGS` for Cmake. – jww Oct 05 '19 at 10:11
  • 1
    I added it to the flags but no luck. Is there any possibility that it's configured somewhere else or would it have to be in the code somewhere? – Jen Oct 08 '19 at 12:10
4

This error often happens when cross-compiling with Rust/Cargo, because Cargo isn't smart enough to find cross-build tools by itself.

You need to set appropriate env vars. In the example replace x86_64_unknown_linux_gnu with your target, and paths to your cross-build paths (the example is for Debian). Watch out the env vars are case-sensitive and inconsistently named!

# for the cc crate
export HOST_CC=gcc
export CC_x86_64_unknown_linux_gnu=/usr/bin/x86_64-linux-gnu-gcc

# for Cargo
export CARGO_TARGET_X86_64-UNKNOWN-LINUX-GNU_LINKER=/usr/bin/x86_64-linux-gnu-gcc
Kornel
  • 97,764
  • 37
  • 219
  • 309
  • 1
    To install it on ARM Fedora: `sudo yum install gcc-c++-x86_64-linux-gnu` – sffc Nov 21 '22 at 01:20
  • On ubuntu this should be `sudo apt install gcc-i686-linux-gnu` for `x86_64` and `sudo apt install gcc-aarch64-linux-gnu` for `aarch64`. – darkdragon Jun 16 '23 at 21:59
0

On the arm64 machine or container, install x86_64-linux-gnu-gcc , debian:bookworm is what I'm using.

# apt-get install g++-x86-64-linux-gnu libc6-dev-amd64-cross

Maybe you need to install other amd64 libs

# dpkg --add-architecture amd64 
# apt-get update
# apt-get install libjpeg-dev:amd64
Jack
  • 111
  • 2
  • 4
-1

For M1/M2, if you want to compile x86, x86_64, do this:

x86_64-linux-gnu-gcc -o hello_x64 -m64 hello.c
x86_64-linux-gnu-gcc -o hello_x32 -m32 hello.c
Smile.Hunter
  • 224
  • 4
  • 14