xoolive / geodesy

A pragmatic and efficient geodesy toolkit
MIT License
7 stars 7 forks source link

Issues with META file for `ocamlfind` #2

Closed xoolive closed 8 years ago

xoolive commented 8 years ago

The linkopts = "-cc @CMAKE_CXX_COMPILER@" in ocaml/META.in seems irrelevant, and even buggy when compiling/ocamlfind-ing with Windows.

The linker should be specified instead of the compiler (hence flexlink), and their options as well (if need be.)

See, -chain mingw or -chain cygwin.

Question:

  1. Is this line really necessary?
  2. Are there any changes to do in ocaml-cmake so that everything works great?
xoolive commented 8 years ago

poke @jbedouet

xoolive commented 8 years ago

This line is at least necessary under Linux, so that the resulting executable is linked towards C++ and not C. When used with Windows, flexlink does the linking, regardless of C++/C.

The best option may be to create a C interface (extern "C") uphill (for the functions called by the OCaml callbacks) so that the linking is more direct. Would it be?

xoolive commented 8 years ago

Also, it is weird that the linkopts option is not considered when creating an interpreter through ocamlmktop. See example below:

xo at tsugaru in ~
$ ocaml
        OCaml version 4.02.0

# #use "topfind";;
- : unit = ()
Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

- : unit = ()
# #require "geodesy";;
/home/xo/.opam/4.02.0+PIC/lib/geodesy: added to search path
/home/xo/.opam/4.02.0+PIC/lib/geodesy/geodesy-byte.cma: loaded
# open Geodesy;;
# SphericalGeodesy.distance 0. 0. 0. (1./.60. *. acos(-1.)/. 180.);;
Error: The external function `sph_distance' is not available
xo at tsugaru in ~
$ ocamlfind ocamlmktop -package geodesy -linkpkg -cc "/usr/bin/c++"
xo at tsugaru in ~
$ ./a.out
        OCaml version 4.02.0

# open Geodesy;;
Error: Unbound module Geodesy
# #use "topfind";;
- : unit = ()
Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

- : unit = ()
# #require "geodesy";;
/home/xo/.opam/4.02.0+PIC/lib/geodesy: added to search path
/home/xo/.opam/4.02.0+PIC/lib/geodesy/geodesy-byte.cma: loaded
# open Geodesy;;
# SphericalGeodesy.distance 0. 0. 0. (1./.60. *. acos(-1.)/. 180.);;
- : float = 1853.2487774093122
#