我正在尝试使用 Mono 的 mkbundle 工具从 AMD64 系统(在 VM 中运行的 Ubuntu 14.04)为 ARM(RaspberryPi)编译本机应用程序。
Mono 版本是 4.4.2.11(最新,在这样做的时候),从Mono 的包存储库安装,但也尝试使用 4.2.3.4。
我在跑:
export CC="/usr/bin/arm-linux-gnueabi-gcc"
export AS="/usr/arm-linux-gnueabi/bin/as"
/usr/bin/mkbundle --static --deps --skip-scan \
-o artifacts/MyApp \
bin/Debug/MyApp.exe bin/Debug/*.dll
如果我在 RaspberryPi 本身上运行它,这很好用(尽管我不需要设置 CC 和 AS 变量)。
如果我从我的 AMD64 VM 运行它,它最终会运行以下命令:
/usr/bin/arm-linux-gnueabi-gcc -o artifacts/MyApp -Wall \
-D_REENTRANT -I/usr/lib/pkgconfig/../../include/mono-2.0 \
temp.c \
-L/usr/lib/pkgconfig/../../lib \
-Wl,-Bstatic -lmono-2.0 -Wl,-Bdynamic \
-lm -lrt -ldl -lpthread \
temp.o
结果是:
/usr/lib/pkgconfig/../../lib/libmono-2.0.a:添加符号时出错:文件格式无法识别 collect2:错误:ld 返回 1 退出状态
意识到它libmono-2.0.a
来自特定于架构的包,我从http://download.mono-project.com/repo/debian/pool/main/m/mono/下载了 armel 架构包并将其解压缩到我的主目录中(所以有一个/home/gregmac/libmono-armel/usr/lib/libmono-2.0.a
),然后尝试:
/usr/bin/arm-linux-gnueabi-gcc -o artifacts/MyApp -Wall \
-D_REENTRANT -I/home/gregmac/libmono-armel/usr/include/mono-2.0 \
temp.c \
-L/home/gregmac/libmono-armel/usr/lib \
-Wl,-Bstatic -lmono-2.0 -Wl,-Bdynamic \
-lm -lrt -ldl -lpthread \
-v \
temp.o
我也尝试将 LIBRARY_PATH 和 LD_LIBRARY_PATH 设置为/home/gregmac/libmono-armel/usr/lib
,但总是遇到同样的问题。
完整输出(包括 -v 选项):
Using built-in specs.
COLLECT_GCC=/usr/bin/arm-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.3-12ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,
obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr
/arm-linux-gnueabi/include/c++/4.7.3 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-gnu-unique-object --disable-libmudflap --dis
able-libitm --enable-plugin --with-system-zlib --enable-objc-gc --with-cloog --enable-cloog-backend=ppl --disable-cloog-version-check --disable-ppl-version-check --enable-multiarch --e
nable-multilib --disable-sjlj-exceptions --with-arch=armv5t --with-float=soft --disable-werror --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-l
inux-gnueabi --program-prefix=arm-linux-gnueabi- --includedir=/usr/arm-linux-gnueabi/include
Thread model: posix
gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-12ubuntu1)
COLLECT_GCC_OPTIONS='-o' 'artifacts/MyApp' '-Wall' '-D' '_REENTRANT' '-I' '/home/gregmac/libmono-armel/usr/include/mono-2.0' '-L/home/gregmac/libmono-armel/usr/lib' '-v' '-march=armv5t' '-mfloat-abi=soft' '-mtls-dialect=gnu'
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/cc1 -quiet -v -I /home/gregmac/libmono-armel/usr/include/mono-2.0 -imultilib sf -imultiarch arm-linux-gnueabi -D _REENTRANT temp.c -quiet -dumpbase temp.c -march=armv5t -mfloat-abi=soft -mtls-dialect=gnu -auxbase temp -Wall -version -fstack-protector -o /tmp/cchyLX23.s
GNU C (Ubuntu/Linaro 4.7.3-12ubuntu1) version 4.7.3 (arm-linux-gnueabi)
compiled by GNU C version 4.8.2, GMP version 5.1.3, MPFR version 3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/arm-linux-gnueabi"
ignoring nonexistent directory "/usr/include/arm-linux-gnueabi"
#include "..." search starts here:
#include <...> search starts here:
/home/gregmac/libmono-armel/usr/include/mono-2.0
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/include
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/include-fixed
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/include
/usr/include
End of search list.
GNU C (Ubuntu/Linaro 4.7.3-12ubuntu1) version 4.7.3 (arm-linux-gnueabi)
compiled by GNU C version 4.8.2, GMP version 5.1.3, MPFR version 3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 550509f4ff92bab4626b84fc11f267f2
temp.c: In function ‘install_dll_config_files’:
temp.c:59:2: warning: pointer targets in passing argument 2 of ‘mono_register_config_for_assembly’ differ in signedness [-Wpointer-sign]
In file included from temp.c:2:0:
/home/gregmac/libmono-armel/usr/include/mono-2.0/mono/metadata/assembly.h:102:24: note: expected ‘const char *’ but argument is of type ‘const unsigned char *’
COLLECT_GCC_OPTIONS='-o' 'artifacts/MyApp' '-Wall' '-D' '_REENTRANT' '-I' '/home/gregmac/libmono-armel/usr/include/mono-2.0' '-L/home/gregmac/libmono-armel/usr/lib' '-v' '-march=armv5t' '-mfloat-abi=soft' '-mtls-dialect=gnu'
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/as -v -I /home/gregmac/libmono-armel/usr/include/mono-2.0 -march=armv5t -mfloat-abi=soft -meabi=5 -o /tmp/ccbJ6Gk5.o /tmp/cchyLX23.s
GNU assembler version 2.24 (arm-linux-gnueabi) using BFD version (GNU Binutils for Ubuntu) 2.24
COMPILER_PATH=/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/:/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/:/usr/lib/gcc-cross/arm-linux-gnueabi/:/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/:/usr/lib/gcc-cross/arm-linux-gnueabi/:/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/
LIBRARY_PATH=/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/lib/../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/:/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/lib/:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-o' 'artifacts/MyApp' '-Wall' '-D' '_REENTRANT' '-I' '/home/gregmac/libmono-armel/usr/include/mono-2.0' '-L/home/gregmac/libmono-armel/usr/lib' '-v' '-march=armv5t' '-mfloat-abi=soft' '-mtls-dialect=gnu'
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/collect2 --sysroot=/ --build-id --eh-frame-hdr -dynamic-linker /lib/ld-linux.so.3 -X --hash-style=gnu --as-needed -m armelf_linux_eabi -z relro -o artifacts/MyApp /usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/lib/../lib/crt1.o /usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/lib/../lib/crti.o /usr/lib/gcc-cross/arm-linux-gnueabi/4.7/crtbegin.o -L/home/gregmac/libmono-armel/usr/lib -L/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/lib/../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc-cross/arm-linux-gnueabi/4.7 -L/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/lib /tmp/ccbJ6Gk5.o -Bstatic -lmono-2.0 -Bdynamic -lm -lrt -ldl -lpthread temp.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc-cross/arm-linux-gnueabi/4.7/crtend.o /usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/lib/../lib/crtn.o
/usr/lib/../lib/libmono-2.0.a: error adding symbols: File format not recognized
collect2: error: ld returned 1 exit status
我也尝试了相同的命令,但没有--static
,并得到相同的错误,但关于.so
而不是.a
文件:
/usr/lib/pkgconfig/../../lib/libmono-2.0.so:文件无法识别:文件格式无法识别 collect2:错误:ld 返回 1 退出状态
我在这里遗漏了一些明显的东西吗?为什么 gcc 仍在寻找/usr/lib/
而不是/home/gregmac/libmono-armel/usr/lib
?我应该设置其他一些环境变量,以便原始mkbundle
命令可以正确调用它吗?