简体   繁体   English

OCaml如何建立静态项目

[英]OCaml how to build statically project

I've to prepare my OCaml project to compile/link/run on system where some libraries are not availible (yojson, curl, cryptokit but it's probably not so important) how may I do it? 我必须准备OCaml项目,以便在某些库不可用的系统上编译/链接/运行(yojson,curl,cryptokit,但可能并不那么重要),我该怎么办?

So far I was using: 到目前为止,我正在使用:

$ ocamlbuild -use-ocamlfind -pkgs curl,yojson,netstring,cryptokit,netclient,lablgtk2.auto-init,pgocaml tweetomat.native

it obviously won't work if some packages are missing. 如果缺少某些软件包,它将显然无法正常工作。 My attempt was to look for libraries path typing 我的尝试是寻找库路径类型

$ ocamlfind printconf path

and manually copy missing libraries' folders to project's folder, here is listining of them 并手动将丢失的库的文件夹复制到项目的文件夹,这里列出了它们

$ tree -r libs

libs/
├── yojson
│   ├── yojson.o
│   ├── yojson.mli
│   ├── yojson.cmx
│   ├── yojson.cmo
│   ├── yojson.cmi
│   ├── yojson_biniou.o
│   ├── yojson_biniou.mli
│   ├── yojson_biniou.cmx
│   ├── yojson_biniou.cmo
│   ├── yojson_biniou.cmi
│   └── META
├── curl
│   ├── META
│   ├── libcurl-helper.a
│   ├── curl.mli
│   ├── curl.cmxa
│   ├── curl.cmi
│   ├── curl.cma
│   └── curl.a
└── cryptokit
    ├── META
    ├── libcryptokit_stubs.a
    ├── cryptokit.mli
    ├── cryptokit.cmxs
    ├── cryptokit.cmxa
    ├── cryptokit.cmx
    ├── cryptokit.cmi
    ├── cryptokit.cma
    └── cryptokit.a

Ok so I tried to compile step-by-step every single file from project and then compile everything to executable using: 好的,所以我尝试逐步编译项目中的每个文件,然后使用以下命令将所有文件编译为可执行文件:

$ ocamlc -c twitter_oauth.mli
$ ocamlfind ocamlc -package netstring,netclient -I ./libs/cryptokit/ \
    -c twitter_oauth.ml
$ ocamlc -c connection.mli
$ ocamlfind ocamlc -I ./libs/curl/ -c connection.ml
$ ocamlfind ocamlc -I ./libs/yojson/ -c parser.ml
$ ocamlfind ocamlc -package pgocaml -c sql.ml
$ ocamlfind ocamlc -package lablgtk2.auto-init,pgocaml -c gui.ml
$ ocamlfind ocamlc -package lablgtk2.auto-init,pgocaml,netstring,netclient \
    -I ./libs/cryptokit/ -I ./libs/curl/ -I ./libs/yojson/ -o tweetomat \
    yojson.cmo curl.cma cryptokit.cma \
    twitter_oauth.cmo connection.cmo parser.cmo sql.cmo gui.cmo

but I'm getting: 但我得到:

File "_none_", line 1:
Error: Error while linking ./libs/yojson/yojson.cmo:
Reference to undefined global `Bi_outbuf'

I googled a little and it looks like yojson is not built statically and needs 'biniou' library to fullfill dependencies (I'm not sure about statically build but it looks like that). 我用谷歌搜索了一下,看起来yojson不是静态构建的,需要'biniou'库来完全填充依赖项(我不确定静态构建,但看起来像那样)。 And in fact after changing last command to (changes are marked by asterisks): 实际上,将最后一个命令更改为(更改后用星号标记):

$ ocamlfind ocamlc -package lablgtk2.auto-init,**biniou**,pgocaml,netstring,netclient \
    -I ./libs/cryptokit/ -I ./libs/curl/ -I ./libs/yojson/ -o tweetomat \
    **biniou.cma** yojson.cmo curl.cma cryptokit.cma \
    twitter_oauth.cmo connection.cmo parser.cmo sql.cmo gui.cmo

previous error does not occur but I've new one: 以前的错误不会发生,但是我是新错误:

File "_none_", line 1:
Error: Error while linking ./libs/yojson/yojson.cmo:
Reference to undefined global `Easy_format'

oh god I won't include every single library on which yojson/curl/cryptokit depends >:(. Can you help me guys? Moreover does there exist some simpler way to do that using ocamlbuild? 哦,天哪,我不会提供yojson / curl / cryptokit依赖的每个库> :(.。您能帮我吗?此外,是否存在使用ocamlbuild来实现此目的的更简单方法?

Don't specify include paths for dependencies manually - let ocamlfind handle it. 不要手动指定依赖项的包含路径-让ocamlfind处理它。 So the question remains on how to make that libraries available via ocamlfind . 因此,问题仍然在于如何通过ocamlfind使该库可用。

Either: 或者:

  • Use opam to download and install missing dependencies 使用opam下载并安装缺少的依赖项
  • If opam dependency is not an option - distribute other libraries as tarballs together with your project and make the build script unpack and build them when needed (build steps may be different for each library) - and install as usual (via ocamlfind ). 如果不能选择opam依赖-将其他库作为tarball分发到您的项目中,并使构建脚本解包并在需要时进行构建(每个库的构建步骤可能不同)-并照常安装(通过ocamlfind )。

    There may be a problem of ocamlfind installing into system directory writable by root only. ocamlfind安装到只能由root写入的系统目录中可能存在问题。 This can be handled by setting environment variable telling another directory for ocamlfind to install to and lookup from. 可以通过设置环境变量告诉ocamlfind要安装到该目录并ocamlfind查找的另一个目录来处理。

    That would be manual bundling until we have it automatic from opam one day. 那将是手动捆绑,直到我们有一天从opam自动将其捆绑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM