Closed holocronweaver closed 8 years ago
Oddly running make all in the build directory seems to complete successfully.
That's not a cross-build.
I will take a look shortly.
What is the exact compiler configuration you are using? (the conf-android
installation command)
ARCH=arm SUBARCH=armv7 SYSTEM=linux_eabi CCARCH=arm TOOLCHAIN=arm-linux-androideabi-4.9 TRIPLE=arm-linux-androideabi LEVEL=19 STLVER=4.9 STLARCH=armeabi opam reinstall conf-android
OK so here's your problem: API level 19 is not supported with ctypes.
- In file included from /tmp/ctypes_libffi_configd73136.c:3:0:
- /home/whitequark/.opam/4.02.3+32bit/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/complex.h:42:46: warning: missing terminating ' character
- # error Cannot include both <complex> and C99's <complex.h>
- ^
- /home/whitequark/.opam/4.02.3+32bit/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/complex.h:47:26: fatal error: complex.h: No such file or directory
- #include_next <complex.h>
- ^
- compilation terminated.
You can apply the following patch to ctypes to make it compile. This will require you to create an OPAM overlay (copy the packages/ctypes-android.0.6.1
somewhere then opam repo add overlay .
there), put this patch into files/patches/backport-complex.patch
, then add a patches: ["patches/backport-complex.patch"]
to the opam
file).
--- a/src/configure/extract_from_c.ml Wed Jul 13 10:02:47 2016
+++ b/src/configure/extract_from_c.ml Wed Jul 13 10:02:49 2016
@@ -54,7 +54,7 @@
let headers = "\
#include <stdint.h>
#include <stdbool.h>
-#include <complex.h>
+//#include <complex.h>
#include <inttypes.h>
#include <caml/mlvalues.h>
"
--- a/src/configure/gen_c_primitives.ml Wed Jul 13 10:02:58 2016
+++ b/src/configure/gen_c_primitives.ml Wed Jul 13 10:03:00 2016
@@ -51,8 +51,8 @@
c_primitive "Uint64_t" "uint64_t" (Defined_format "PRIu64");
c_primitive "Float" "float" (Known_format ".12g");
c_primitive "Double" "double" (Known_format ".12g");
- c_primitive "Complex32" "float complex" (No_format);
- c_primitive "Complex64" "double complex" (No_format);
+ c_primitive "Complex32" "float _Complex" (No_format);
+ c_primitive "Complex64" "double _Complex" (No_format);
c_primitive "Nativeint" "intnat" (Defined_format "REAL_ARCH_INTNAT_PRINTF_FORMAT \"d\"");
{ constructor = "Camlint";
typ = "camlint";
I followed your instructions, and the patch seems to be applied correctly, but I get a similar error from a different file:
# In file included from /home/jesse/.opam/4.02.3+32bit/build/ctypes-android.0.6.1/src/ctypes/complex_stubs.c:8:0:
# /home/jesse/.opam/4.02.3+32bit/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/complex.h:42:46: warning: missing terminating ' character
# # error Cannot include both <complex> and C99's <complex.h>
# ^
# /home/jesse/.opam/4.02.3+32bit/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/complex.h:47:26: fatal error: complex.h: No such file or directory
# #include_next <complex.h>
# ^
Do these files c files need to be patched as well, or is there another ocaml generator file that needs patching?
Hm, weird, I recall compiling it successfully... in any case complex stubs should be handwritten, so just another patch.
Sorry to revive this issue but what's the status with using ctypes. Do we need to cross compile the C code separately for ARM and then link it after the fact? Or can this tool chain compile the actual C as well.
@lingz It can. Compile the C code with ocamlfind -toolchain android ocamlc foo.c
.
And I guess I can also use ocamlopt and directly use linker flags and c flags as usual to link to both static and dynamic libraries?
No. ocamlc only knows the flags for compiling a C file to an object file.
To link something, you need to make an opam package for your project, and then use the opam variables from the conf-android package. E.g. see how bzip2-sys-android does it: https://github.com/whitequark/opam-cross-android/blob/master/packages/bzip2-sys-android.1.0.6/opam
Ok, may have an actual bug this time. ctypes 0.6.1 fails to compile. See log.
Oddly running
make all
in the build directory seems to complete successfully.