mlton 给出与库相关的错误

mlton gives library-related error

当我尝试用 mlton 编译程序时,出现错误。

~/projects/serve-sml $ mlton server.mlb
In file included from /usr/lib/mlton/include/platform.h:13:0,
                 from /usr/lib/mlton/include/common-main.h:16,
                 from /usr/lib/mlton/include/amd64-main.h:11,
                 from /tmp/file86PWQJ.1.c:110:
/usr/lib/mlton/include/cenv.h:137:17: fatal error: gmp.h: No such file or directory
 #include "gmp.h"
                 ^
compilation terminated.
call to system failed with exit status 1:
gcc -std=gnu99 -c -I/usr/lib/mlton/targets/self/include -I/usr/lib/mlton/include -O1 -fno-common -fno-strict-aliasing -fomit-frame-pointer -w -m64 -o /tmp/fileg5D5To.o /tmp/file86PWQJ.1.c
~/projects/serve-sml $ 

根据 this,这意味着我应该安装 libgmp3-dev。我已经 运行 apt-get install libgmp3-dev,并验证文件 /usr/include/x86_64-linux-gnu/gmp.h 存在,但我仍然遇到同样的错误。

知道我做错了什么吗?

尝试在您的终端中执行 gcc -v -x c -E -。这将打印出您的 C 编译器正在使用的头文件搜索路径。我得到类似的东西:

#include "..." search starts here:
#include <...> search starts here:
/Users/ml9951/include
.
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)

因此,如果我在 /usr/include/x86_64-linux-gnu/ 中有 gmp.h,那么我的 C 编译器将找不到它。我建议将您的 .h 文件移动到此搜索路径上的目录(如 /usr/local/include 在我的例子中),或传入 -I /usr/include/x86_64-linux-gnu/ 标志,这将需要修改 MLton 的构建脚本。当 link

时,您可能不得不对 libgmp.a 做同样的事情