fdopen / ppx_cstubs

preprocessor for easier stub generation with ocaml-ctypes
https://fdopen.github.io/ppx_cstubs/
Other
55 stars 5 forks source link

Fix for compilation error in ppx_cstubs examples #6

Closed sidkshatriya closed 3 years ago

sidkshatriya commented 3 years ago

When issuing make in the ppx_cstubs examples subfolder the following problem is encountered:

ocamlfind: [WARNING] Package `threads': Linking problems may arise because of the missing -thread or -vmthread switch

This eventually ends up in a compiler error:

File "ftw.ml", line 1:
Error: No implementations provided for the following modules:
         Thread referenced from [ETC. ETC.]/_opam/lib/ctypes/ctypes-foreign.cmxa(Foreign)
         Mutex referenced from [ETC. ETC]/_opam/lib/ctypes/ctypes-foreign.cmxa(Foreign)

Other examples e.g. inline.exe etc. also complain about missing -thread

This PR fixes the compilation problem by adding -thread to examples/Makefile


Additionally, I receive the following c-compiler warnings while running make in the examples folder:

ftw_stubs.c: In function ‘ppxc_ftw_c_bf_ftw’:
ftw_stubs.c:75:26: warning: passing argument 2 of ‘ftw’ from incompatible pointer type [-Wincompatible-pointer-types]
   75 |   ppxc__7 = ftw(ppxc__1, ppxc__3, ppxc__5);
      |                          ^~~~~~~
      |                          |
      |                          ppxc_ftw_c_bf_typedef {aka int (*)(char *, void *, int)}
In file included from /usr/include/features.h:461,
                 from /usr/include/x86_64-linux-gnu/bits/libc-header-start.h:33,
                 from /usr/include/limits.h:26,
                 from /usr/lib/gcc/x86_64-linux-gnu/9/include/limits.h:194,
                 from /usr/lib/gcc/x86_64-linux-gnu/9/include/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-linux-gnu/9/include/limits.h:34,
                 from [ETC. ETC.]/o412/_opam/lib/ctypes/ctypes_primitives.h:11,
                 from [ETC. ETC.]/o412/_opam/lib/ctypes/ctypes_cstubs_internals.h:13,
                 from ftw_stubs.c:2:
/usr/include/ftw.h:140:12: note: expected ‘__ftw_func_t’ {aka ‘int (*)(const char *, const struct stat *, int)’} but argument is of type ‘ppxc_ftw_c_bf_typedef’ {aka ‘int (*)(char *, void *, int)’}
  140 | extern int __REDIRECT (ftw, (const char *__dir, __ftw_func_t __func,
      |            ^~~~~~~~~~

Are these warnings harmless?

fdopen commented 3 years ago

Thanks. I've forgot to update it after https://github.com/ocamllabs/ocaml-ctypes/pull/651

The warning is currently unavoidable, because ctypes doesn't support cv type qualifiers: https://github.com/ocamllabs/ocaml-ctypes/issues/134

sidkshatriya commented 3 years ago

Thanks for the super-quick merge!

There is something a bit confusing about getting the examples to work. When you try to run make, it complains about ctypes.foreign library being missing. This can be confusing to someone new to ctypes because the user thinks "Hey I already installed the ctypes package!?".

I needed to google this and the fix, of course, is to install the virtual package ctypes-foreign which enables the ctypes.foreign library in the current switch...

Mentioning this here for anybody's future reference. It would also be great if we somehow made this clear in a README.md or automated this in some other way...