tbeu / matio

MATLAB MAT File I/O Library
https://matio.sourceforge.io
BSD 2-Clause "Simplified" License
334 stars 97 forks source link

Cross compilation fails on configure step #78

Closed cdbrkfxrpt closed 6 years ago

cdbrkfxrpt commented 6 years ago

Hello,

thank you for this great piece of software! I'm packaging matio for Void Linux (https://github.com/voidlinux/void-packages/pull/10554) and have come across

checking for va_copy() function... configure: error: in `/builddir/matio-1.5.11':
configure: error: cannot run test program while cross compiling

during cross compilation. Do you deem it possible to add a configure option to turn of running test programs? I tried turning off checking entirely using ./configure --disable-option-checking to no avail.

Regards Florian

tbeu commented 6 years ago

That va_copy check also makes trouble when I want to compile matio with enabled sanitizer check passed to configure. I'll kindly refer to @papadop who added this check in #30.

papadop commented 6 years ago

Sorry for the delay in the answer. Strictly speaking the test was not added with #30, I modified an existing test (mostly by replacing it by one found on the web). So the test for va_copy was already there and is needed for src/io.c so for the mat_log function.... Totally disabling the test would basically replace the va_copy by memcpy and I do not know the exact consequences of this (depends on the platform and the compiler). The first ref below give a way to temporarily disable it (using the cache var ac_cv_va_copy) if you want to check further while I'm attempting to fix the problem.

Digging a little bit more shows that the new macro (as the old one actually) is using AC_TRY_RUN and that's the culprit of the problem as you cannot execute programs while cross-compiling. As it is the only use of AC_TRY_RUN (as far as I can tell), and AC_TRY_RUN is obsolete, we can replace it with an AC_RUN_IFELSE or even with AC_LINK_IFELSE (as I do not see the result of the test program being used).

@tbeu : Can you provide me with a command line that produces the problem you mention ? That will allow me to do some tests. If this is similar to the reported problem, the solution might also be valid for that case.

Some refs: https://unix.stackexchange.com/questions/248088/cannot-run-test-program-while-cross-compiling-cross-compiling-firebird https://stackoverflow.com/questions/23888063/why-cross-compiling-for-arm-fails-in-configure https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Obsolete-Macros.html https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Runtime.html#AC_RUN_IFELSE

papadop commented 6 years ago

Hum. Unfortunately the test result is used... AC_RUN_IFELSE will be an improvement, but I'm unsure of its reliability in cross-compiling mode (for normal mode, it will do the same as now)....

tbeu commented 6 years ago

Can you provide me with a command line that produces the problem you mention ?

I fail to reproduce. Not sure what changed since then.

cdbrkfxrpt commented 6 years ago

I solved by manually setting on cross compile, i.e.

if [ -n "$CROSS_BUILD" ]; then
    configure_args+=" ac_cv_va_copy=C99"
fi
tbeu commented 6 years ago

Is there anything left to do for me or can we close this as workaround?

cdbrkfxrpt commented 6 years ago

nothing more to do as far as i'm concerned.