提问人:Ben 提问时间:12/8/2021 最后编辑:Ben 更新时间:12/8/2021 访问量:207
编译适用于 linux arm64 的 GCC 时链接 .c 文件的 Makefile 链接器错误
Makefile linker error about linking .c files when compiling GCC for linux arm64
问:
我正在使用 Linux WSL 上的 Android NDK 交叉编译 GCC,因为我的目标是 ARM64 Android。我需要一些 Android 兼容文件,例如(pytorch 需要)这些文件显然是在编译 GCC 时创建的。将来我可能还需要一个可以在 Android 上运行的 GCC 可执行文件。.so
libgomp.so
这是我编写的用于编译 GCC 的构建脚本:
#!/bin/bash
export PATH="/home/ben/.local/bin:/opt/gradle/latest/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/"
BUILD_DIR=./build
GCC_DIR=`realpath gcc`
#CONF_FLAGS="--disable-shared"
CONF_FLAGS="--enable-shared --enable-static"
mkdir $BUILD_DIR
PREFIX=`realpath ./install/`
mkdir $PREFIX
echo "install directory: $PREFIX"
pushd $BUILD_DIR
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
export TARGET=aarch64-linux-android
export API=23
export AR=$TOOLCHAIN/bin/llvm-ar
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export AS=$CC
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export LD=$TOOLCHAIN/bin/ld
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
echo "Cleaning gcc directory via git clean"
pushd $GCC_DIR
git clean -f
popd
$GCC_DIR/configure --host $TARGET --prefix=$PREFIX $CONF_FLAGS
make
popd
我需要重新定义,否则我在makefile中出现语法错误,可能是因为在Windows的PATH中也定义了语法错误。
其他变量的定义如下:https://developer.android.com/ndk/guides/other_build_systemsPATH
make
NDK
指向/home/ben/android-ndk-r23b
./configure
据我所知,似乎已经正确工作,但是当我运行时,过了一会儿,我收到以下错误:make
ld: error: /home/ben/gcc_build/gcc/gcc/c-family/c-opts.c:1090:(.text+0x1F50): improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x1C842A4 is not aligned to 8 bytes
ld: error: /home/ben/gcc_build/gcc/gcc/c-family/c-opts.c:1271:(.text+0x2830): improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x1C842A4 is not aligned to 8 bytes
ld: error: /home/ben/gcc_build/gcc/gcc/c-family/c-opts.c:0:(.text+0x2854): improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x1C842A4 is not aligned to 8 bytes
ld: error: /home/ben/gcc_build/gcc/gcc/read-md.c:137:(.text+0x254): improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x1C842A4 is not aligned to 8 bytes
ld: error: /home/ben/gcc_build/gcc/gcc/read-md.c:197:(.text+0x500): improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x1C842A4 is not aligned to 8 bytes
ld: error: /home/ben/gcc_build/gcc/gcc/toplev.c:697:(.text+0x25F4): improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x1C842A4 is not aligned to 8 bytes
ld: error: /home/ben/gcc_build/gcc/gcc/toplev.c:711:(.text+0x2770): improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x1C842A4 is not aligned to 8 bytes
ld: error: /home/ben/gcc_build/gcc/gcc/gimple-ssa-warn-restrict.c:2159:(.text+0x3AF4): improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x1C842A4 is not aligned to 8 bytes
ld: error: /home/ben/gcc_build/gcc/gcc/ggc-page.c:694:(.text+0x68): improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x1C842A4 is not aligned to 8 bytes
ld: error: /home/ben/gcc_build/gcc/gcc/ggc-page.c:1744:(.text+0xD3C): improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x1C842A4 is not aligned to 8 bytes
ld: error: /home/ben/gcc_build/gcc/gcc/dumpfile.c:0:(.text+0x2A7C): improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x1C842A4 is not aligned to 8 bytes
ld: error: /home/ben/gcc_build/gcc/gcc/dumpfile.c:0:(.text+0x2A9C): improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x1C842A4 is not aligned to 8 bytes
ld: error: /home/ben/gcc_build/gcc/gcc/dumpfile.c:0:(.text+0x30D0): improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x1C842A4 is not aligned to 8 bytes
ld: error: /home/ben/gcc_build/gcc/gcc/dumpfile.c:0:(.text+0x420C): improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x1C842A4 is not aligned to 8 bytes
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
失败的命令是这样的:
/home/ben/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android23-clang++ -no-pie -g -O2 -DIN_GCC -fno-strict-aliasing -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-error=format-diag -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -o cc1 c/c-lang.o c-family/stub-objc.o attribs.o c/c-errors.o c/c-decl.o c/c-typeck.o c/c-convert.o c/c-aux-info.o c/c-objc-common.o c/c-parser.o c/c-fold.o c/gimple-parser.o c-family/c-common.o c-family/c-cppbuiltin.o c-family/c-dump.o c-family/c-format.o c-family/c-gimplify.o c-family/c-indentation.o c-family/c-lex.o c-family/c-omp.o c-family/c-opts.o c-family/c-pch.o c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-pretty-print.o c-family/c-semantics.o c-family/c-ada-spec.o c-family/c-ubsan.o c-family/known-headers.o c-family/c-attribs.o c-family/c-warn.o c-family/c-spellcheck.o aarch64-c.o glibc-c.o \
cc1-checksum.o libbackend.a main.o libcommon-target.a libcommon.a ../libcpp/libcpp.a ../libdecnumber/libdecnumber.a libcommon.a ../libcpp/libcpp.a ./../intl/libintl.a ../libbacktrace/.libs/libbacktrace.a ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a -L/home/ben/gcc_build/build/./gmp/.libs -L/home/ben/gcc_build/build/./mpfr/src/.libs -L/home/ben/gcc_build/build/./mpc/src/.libs -lmpc -lmpfr -lgmp -rdynamic -L./../zlib -lz
我不确定发生了什么,因为它似乎正在尝试链接文件,我认为这不正常。我也不明白这些文件是如何涉及的,因为它们没有出现在命令中,目录也没有。
我不认为在 WSL 中编译是问题,尽管它以前引起了一些问题,但我认为我解决了它们。ld
.c
gcc/gcc/
我能做些什么来解决这个问题?
答: 暂无答案
评论
libgomp.so
libgomp