ampl / mp

An open-source library for mathematical programming
https://mp.ampl.com
Other
229 stars 42 forks source link

Cross-compiling problems #115

Open staticfloat opened 6 years ago

staticfloat commented 6 years ago

Hello, I am trying to cross-compile ASL for a variety of platforms, and I would really like to avoid the bootstrapping issues of generating arith.h and expr-info.cc. As a bit of background, I am trying to build redistributable binaries for the Julia project, and our binary building infrastructure is based on cross-compilation.

Right now, when I try to cross-compile for Windows, it tries to use wine to run the newly created executables, but they look like they're just generating headers/source. Is it possible for ASL to detect we're cross-compiling, and generate the necessary executables for the host build system and use those to generate the headers/source? Or even more simply, is there a way I can manually construct these headers and just use those in my cross-compilation?

Thanks!

staticfloat commented 6 years ago

For the record, I am working around this right now by just precomputing the set of arith.h files that I need across all the platforms that I intend to build for and jamming that into the build tree such that it doesn't need to run wine.

fdabrandao commented 6 years ago

Your current workaround seems to be the easiest option. The arith.h file is generated by https://github.com/ampl/mp/blob/8183be3e486d38d281e0c5a02a1ea4239695035e/src/asl/solvers/arithchk.c which contains lots of conditionals (e.g., checking the size of an int) whose values will depend on the compiler and platform, and therefore are not easy to predict.

staticfloat commented 6 years ago

True; it doesn't look like expr-info.cc changes across architectures though; I believe it should be possible to compile it with $(HOSTCC), and use the output regardless of whether we're cross-compiling or not.

zhihaoy commented 5 years ago

This is necessary to get arm64-windows and arm64-uwp build in vcpkg. (x64-uwp can also benefit from this).

fdabrandao commented 5 years ago

A default arith.h file (https://github.com/ampl/mp/blob/master/src/asl/solvers/arith.h1) was added in d03e486f98ad45b7ec2898480f943e9c846f2df0 so that arithchk is not necessary anymore unless the compiler does not support something in the default arith.h file. If the arith.h file used by default does not match the target architecture, or if the compiler is not sufficiently compatible with gcc or Microsoft C/C++, run cmake -DBUILD=all -DGENERATE_ARITH=true .. to generate an architecture-specific arith.h file with arithchk (just as in the previous procedure).

JackBoosY commented 4 years ago

I can use non-arm executable to generate header files, but I encountered other errors:

WS2_32.Lib(WS2_32.dll) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'ARM64'

After change WS2_32_LIBRARY to ws2_32 in src\amplsig\CMakeLists.txt, it works.