openfst-1.6.5交叉编译失败求助:Linaro GCC编译遇链接警告
Let’s work through those linker warnings you’re hitting when cross-compiling OpenFST 1.6.5 for AArch64 with the Linaro 6.3.1 toolchain. First, we’ll correct a critical mistake in your configure command, then address the root causes of the warnings.
First: Fix the --build Flag
Your original command uses --build=armv8—this is incorrect. The --build parameter should specify the architecture of the machine you’re compiling on (your x86_64 host), not the target device. The --host flag (set to aarch64-linux-gnu) is correct for the target, but this mismatch can throw off configure’s library detection logic, leading to linker warnings.
Solution 1: Explicitly Specify Cross-Compiler Binaries
Instead of letting configure guess which compilers to use, explicitly set CC and CXX to your cross-compiler tools. This ensures the build system uses the correct AArch64 compilers instead of falling back to your host’s x86_64 tools.
Update your configure command to:
./configure --prefix=$(pwd) --enable-static --enable-shared --enable-far --enable-ngram-fsts --build=x86_64 --host=aarch64-linux-gnu CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++
Solution 2: Point to the Cross-Compiler’s Sysroot
The linker warning is likely because it’s looking for system libraries (like libm, libpthread, or libstdc++) in your host’s /lib directory instead of the cross-compiler’s dedicated sysroot. Add the --with-sysroot flag to tell configure where the target system libraries live.
Your cross-compiler’s sysroot path is typically inside your Linaro toolchain directory at:/data/jiachen/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/libc
Modify the configure command to include this:
./configure --prefix=$(pwd) --enable-static --enable-shared --enable-far --enable-ngram-fsts --build=x86_64 --host=aarch64-linux-gnu CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ --with-sysroot=/data/jiachen/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/libc
Solution 3: Force Static Linking for Standard Libraries
If warnings persist about missing shared libraries, you can instruct the linker to use static versions of the GCC and C++ standard libraries. Add LDFLAGS to your configure command:
./configure --prefix=$(pwd) --enable-static --enable-shared --enable-far --enable-ngram-fsts --build=x86_64 --host=aarch64-linux-gnu CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ --with-sysroot=/data/jiachen/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/libc LDFLAGS="-static-libgcc -static-libstdc++"
Solution 4: Clean Up Old Build Artifacts
Leftover files from previous failed builds can cause unexpected issues. Before re-running configure, clean everything up:
make clean rm -rf config.log config.status
Troubleshooting Tip
If you still see warnings, check the config.log file generated by configure. It will have detailed logs of which libraries the linker is trying to find and where it’s looking—this will help you pinpoint exactly which dependency is causing the problem.
内容的提问来源于stack exchange,提问作者JCbupt

