2

I'm trying to use Mono's mkbundle tool to compile a native app for ARM (RaspberryPi) from an AMD64 system (Ubuntu 14.04 running in a VM).

Mono version is 4.4.2.11 (latest, at time of doing this), installed from Mono's package repository, but also tried with 4.2.3.4.

I'm running:

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

This works fine if I run it on the RaspberryPi itself (though I don't need to set the CC and AS variables).

If I run it from my AMD64 VM, it eventually runs the command:

/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

Which results in:

/usr/lib/pkgconfig/../../lib/libmono-2.0.a: error adding symbols: File format not recognized collect2: error: ld returned 1 exit status


Realizing that the libmono-2.0.a comes from an architecture-specific package, I downloaded the armel architecture package from http://download.mono-project.com/repo/debian/pool/main/m/mono/ and extracted it in my home directory (so there is a /home/gregmac/libmono-armel/usr/lib/libmono-2.0.a), then tried:

/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

I've also tried setting LIBRARY_PATH and LD_LIBRARY_PATH to /home/gregmac/libmono-armel/usr/lib, but always getting the same problem.

Full output (including -v option):

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

I've also tried the same command but without --static, and get the same error, but about the .so instead of .a file:

/usr/lib/pkgconfig/../../lib/libmono-2.0.so: file not recognized: File format not recognized collect2: error: ld returned 1 exit status


Am I missing something obvious here? Why is gcc still looking in /usr/lib/ instead of /home/gregmac/libmono-armel/usr/lib? Is there some other environment variable I should be setting so the original mkbundle command can invoke this correctly?

gregmac
  • 24,276
  • 10
  • 87
  • 118
  • what version of mono are you using? every time you report a mono issue or question please specify the version of mono and how did you install it, thank you – knocte May 07 '16 at 06:41
  • @knocte Sorry, missed that detail. Question updated. Fairly sure this is less mono and more of a gcc issue anyway. I've found very little about cross-targeting with mkbundle aside from a few random old mailing list posts. – gregmac May 07 '16 at 17:06
  • True, seems to be gcc issue, but anyway it doesn't hurt to always try with latest mono master. Because after mono 4.2.x was released, it seems there are many mkbundle fixes after: https://github.com/mono/mono/commits/master/mcs/tools/mkbundle – knocte May 09 '16 at 05:13
  • Same result with 4.4.2.11-0xamarin1, though it does have one extra line at the end: `ERROR: [Fail] 256`. – gregmac Sep 06 '16 at 21:09
  • Update if anyone comes across this: I gave up, and just added a RaspberryPi as a build agent to our CI server, and run these builds natively. It's the slowest part of the build but other than that it is no-fuss. – gregmac Jan 08 '17 at 18:40

0 Answers0