coin-or-tools / ThirdParty-ASL

COIN-OR autotools harness to build AMPL Solver Library
Eclipse Public License 1.0
5 stars 6 forks source link

Cross-compiling issue #5

Closed AntonJoha closed 1 year ago

AntonJoha commented 2 years ago

I'm currently on Ubuntu x86_64 trying to cross-compile for aarch64. The configuration stage works as expected by running ./configure --host=aarch64-none-linux-gnu

However it fails during the make stages. Reason being (I think) that it's compiling a file for aarch64 and then attempting to run it.

$ make
  CC       solvers/arithchk-arithchk.o
  CC       arithchk-fpinit.o
  CCLD     arithchk
./arithchk > arith.h
/bin/sh: ./arithchk: cannot execute binary file: Exec format error
make: *** [Makefile:1351: arith.h] Error 126

I'm trying to get around this as the program seems to just output a few lines.

More output

Not sure if this is of any use, but here's the output from the other command

./configure --host=aarch64-none-linux-gnu
checking build system type... x86_64-pc-linux-gnu
checking host system type... aarch64-none-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for aarch64-none-linux-gnu-strip... aarch64-none-linux-gnu-strip
checking for a race-free mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking whether make supports the include directive... yes (GNU style)
checking for aarch64-none-linux-gnu-gcc... aarch64-none-linux-gnu-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether aarch64-none-linux-gnu-gcc accepts -g... yes
checking for aarch64-none-linux-gnu-gcc option to enable C11 features... none needed
checking whether aarch64-none-linux-gnu-gcc understands -c and -o together... yes
checking dependency style of aarch64-none-linux-gnu-gcc... gcc3
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by aarch64-none-linux-gnu-gcc... /home/a415278/armcross/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/aarch64-none-linux-gnu/bin/ld
checking if the linker (/home/a415278/armcross/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/aarch64-none-linux-gnu/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /home/a415278/armcross/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-nm -B
checking the name lister (/home/a415278/armcross/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to aarch64-none-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /home/a415278/armcross/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/aarch64-none-linux-gnu/bin/ld option to reload object files... -r
checking for aarch64-none-linux-gnu-objdump... aarch64-none-linux-gnu-objdump
checking how to recognize dependent libraries... pass_all
checking for aarch64-none-linux-gnu-dlltool... no
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for aarch64-none-linux-gnu-ar... aarch64-none-linux-gnu-ar
checking for archiver @FILE support... @
checking for aarch64-none-linux-gnu-strip... (cached) aarch64-none-linux-gnu-strip
checking for aarch64-none-linux-gnu-ranlib... aarch64-none-linux-gnu-ranlib
checking command to parse /home/a415278/armcross/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-nm -B output from aarch64-none-linux-gnu-gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for aarch64-none-linux-gnu-mt... no
checking for mt... mt
configure: WARNING: using cross tools not prefixed with host triplet
checking if mt is a manifest tool... no
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for aarch64-none-linux-gnu-ar... (cached) aarch64-none-linux-gnu-ar
checking the archiver (aarch64-none-linux-gnu-ar) interface... ar
checking for objdir... .libs
checking if aarch64-none-linux-gnu-gcc supports -fno-rtti -fno-exceptions... no
checking for aarch64-none-linux-gnu-gcc option to produce PIC... -fPIC -DPIC
checking if aarch64-none-linux-gnu-gcc PIC flag -fPIC -DPIC works... yes
checking if aarch64-none-linux-gnu-gcc static flag -static works... yes
checking if aarch64-none-linux-gnu-gcc supports -c -o file.o... yes
checking if aarch64-none-linux-gnu-gcc supports -c -o file.o... (cached) yes
checking whether the aarch64-none-linux-gnu-gcc linker (/home/a415278/armcross/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/aarch64-none-linux-gnu/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: libtool version info: -version-number 2:0:0
checking for getrusage... yes
checking for long long... yes
checking for ssize_t... yes
checking for dlopen in -ldl... yes
checking for library containing cos... -lm
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating coinasl.pc
config.status: linking solvers/stdio1.h0 to stdio1.h
config.status: linking solvers/fpinit.c to fpinit.c
config.status: executing depfiles commands
config.status: executing libtool commands
configure: Configuration of ThirdPartyASL successful
svigerske commented 2 years ago

That reason is correct. ASL traditionally executes a small program to determine some system specifics, which are written into arith.h, which is then used to build the ASL lib itself.

Recent ASL includes an alternative of arith.h for "systems with compilers sufficiently compatible with gcc or Microsoft C/C++". We should probably use this when cross-compiling is enabled.
A quick patch that you could try would be

diff --git a/Makefile.in b/Makefile.in
index 838764e..0ff20d3 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1347,9 +1347,8 @@ uninstall-am: uninstall-libLTLIBRARIES uninstall-pkgconfiglibDATA \
 .PRECIOUS: Makefile

-arith.h : arithchk$(EXEEXT)
-       ./arithchk$(EXEEXT) > $@
-@ASL_INT64_TRUE@       echo "#define ASL_big_goff" >> $@
+arith.h : $(srcdir)/solvers/arith.h1
+       cp $^ $@

 details.c :
        echo "char sysdetails_ASL[] = \"$(build)\";" > $@
AntonJoha commented 2 years ago

Thanks for the help!

Not sure if you want this closed or not, so I'll leave that up to you.

svigerske commented 2 years ago

On master, arith.h1 is now used if cross-compiling. If noone complains for a while, we can also put this into stable/2.0 and make a new release.

svigerske commented 1 year ago

OK, it has been a realy long while. The change has now been released with 2.0.1.