compilationldstatic-linkingmlton

MLton compile statically


I've got an issue with the compilation of a program in Standard ML.

This program is working perfectly and compiling perfectly on my local machine. But I would like to be able to compile it statically in order to execute it somewhere else on a Cluster.

Here is the command that I'm using to compile my program :

mton -verbose 3 -codegen native -output spartacus src/spartacus.mlb

Here is the file src/spartacus.mlb :

/usr/lib/mlton/sml/basis/basis.mlb
/usr/lib/mlton/sml/smlnj-lib/Util/smlnj-lib.mlb
/usr/lib/mlton/sml/mlyacc-lib/mlyacc-lib.mlb

util/listsort.sig.sml
util/listsort.sml

smlnj-lib/Binarymap.sml
smlnj-lib/Binaryset.sml

ds/dict.sig.sml
ds/binarydict.sml
ds/dynarraydict.sml

core/settings.sml

util/debug.sml
util/util.sml
util/exn.sig.sml
util/exn.sml
util/ref.sig.sml
util/ref.sml

ds/ubtree.sig.sml
ds/ubtree.sml
ds/bitmatrix.sig.sml
ds/bitmatrix.sml
ds/btprioq.sig.sml
ds/btprioq.sml

core/relationmgr.sig.sml
core/relationmgr.sml

preprocessing/parsetree.sml

core/term.sml

parsers/owlfs/owlfs.grm.sig
parsers/owlfs/owlfs.lex.sml
parsers/owlfs/owlfs.grm.sml
parsers/owlfs/owlfsparser.sml

parsers/lwb/lwb.grm.sig
parsers/lwb/lwb.lex.sml
parsers/lwb/lwb.grm.sml
parsers/lwb/lwbparser.sml

parsers/parser/grmspec.grm.sig
parsers/parser/lexspec.lex.sml
parsers/parser/grmspec.grm.sml
parsers/parser/parser.sml

parsers/ksatc/ksatc.grm.sig
parsers/ksatc/ksatc.lex.sml
parsers/ksatc/ksatc.grm.sml
parsers/ksatc/ksatcparser.sml

parsers/intohylo/intohylo.grm.sig
parsers/intohylo/intohylo.lex.sml
parsers/intohylo/intohylo.grm.sml
parsers/intohylo/intohyloparser.sml

parsers/alc/alc.grm.sig
parsers/alc/alc.lex.sml
parsers/alc/alc.grm.sml
parsers/alc/alcparser.sml

parsers/dimacs/dimacs.grm.sig
parsers/dimacs/dimacs.lex.sml
parsers/dimacs/dimacs.grm.sml
parsers/dimacs/dimacsparser.sml

parsers/dfg/dfg.grm.sig
parsers/dfg/dfg.lex.sml
parsers/dfg/dfg.grm.sml
parsers/dfg/dfgparser.sml

parsers/advtkb/tkbtree.sml
parsers/advtkb/advtkb.grm.sig
parsers/advtkb/advtkb.lex.sml
parsers/advtkb/advtkb.grm.sml
parsers/advtkb/advtkbparser.sml

parsers/tancs/tancs.grm.sig
parsers/tancs/tancs.lex.sml
parsers/tancs/tancs.grm.sml
parsers/tancs/tancsparser.sml

preprocessing/translator.sig.sml
preprocessing/translator.sml

util/dependency.sig.sml
util/dependency.sml

heuristics/penaltymap.sig.sml
heuristics/penaltymap.sml
heuristics/disjunctionpenalties.sig.sml
heuristics/disjunctionpenalties.sml

core/agenda.sig.sml
core/agenda.sml

ds/propstore.sig.sml
ds/propstore.sml
ds/termstore.sig.sml
ds/termstore.sml

opt/lazystore.sig.sml
opt/lazystore.sml
opt/lazyboxstore.sig.sml
opt/lazyboxstore.sml
opt/lazynomstore.sig.sml
opt/lazynomstore.sml

core/universalstore.sig.sml
core/universalstore.sml

core/existentialstore.sig.sml
core/existentialstore.sml

opt/cache.sig.sml
opt/treecache.sml
opt/mtrxcache.sml
opt/cache.sml

core/node.sig.sml
core/node.sml
core/nodestore.sig.sml
core/nodestore.sml

blocking/patternstore.sig.sml
blocking/listpatternstore.sml
blocking/treepatternstore.sml
blocking/mtrxpatternstore.sml
blocking/patternstore.sml
blocking/blockingmgr.sig.sml
blocking/blockingmgr.sml

core/branchingmgr.sig.sml
core/branchingmgr.sml
core/solver.sig.sml
core/solver.sml

output/helpmsg.sml
output/printsettings.sml
output/csvoutput.sml
output/modeloutput.sml
preprocessing/parser.sml
preprocessing/readargs.sml

core/main.sml

And here is the StackTrace of the last part of the compilation :

Compile and Assemble starting
        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/file97aS8t.o \
            /tmp/fileTVXUNZ.16.c
        gcc -c -m64 -o /tmp/fileEW5l8Q.o /tmp/filelhsimY.15.s
        gcc -c -m64 -o /tmp/filea6cMXC.o /tmp/fileGkFaoi.14.s
        gcc -c -m64 -o /tmp/filefyCq0e.o /tmp/fileXt7CAu.13.s
        gcc -c -m64 -o /tmp/file6aM9Ln.o /tmp/filemFDLpo.12.s
        gcc -c -m64 -o /tmp/file0xIwuN.o /tmp/fileRzsHqU.11.s
        gcc -c -m64 -o /tmp/file1sxl2Y.o /tmp/fileqwIZGn.10.s
        gcc -c -m64 -o /tmp/filetuKGWV.o /tmp/fileTg7gK0.9.s
        gcc -c -m64 -o /tmp/filebtu3gE.o /tmp/fileLAXFmK.8.s
        gcc -c -m64 -o /tmp/file0pRNH2.o /tmp/fileNOAFB8.7.s
        gcc -c -m64 -o /tmp/fileTxaQrb.o /tmp/fileWkQghY.6.s
        gcc -c -m64 -o /tmp/fileqh3aE2.o /tmp/filesqqcMD.5.s
        gcc -c -m64 -o /tmp/fileYYijnB.o /tmp/fileaRCFoK.4.s
        gcc -c -m64 -o /tmp/file7xPbic.o /tmp/fileXYwRmD.3.s
        gcc -c -m64 -o /tmp/fileVsXNP1.o /tmp/filefrBd1m.2.s
        gcc -c -m64 -o /tmp/fileykpidV.o /tmp/fileMIX5MM.1.s
        gcc -c -m64 -o /tmp/file4eH2rC.o /tmp/filegwauVv.0.s
     Compile and Assemble finished in 0.96 + 0.00 (0% GC)
     Link starting
        gcc -o spartacus /tmp/file97aS8t.o /tmp/fileEW5l8Q.o /tmp/filea6cMXC.o \
            /tmp/filefyCq0e.o /tmp/file6aM9Ln.o /tmp/file0xIwuN.o \
            /tmp/file1sxl2Y.o /tmp/filetuKGWV.o /tmp/filebtu3gE.o \
            /tmp/file0pRNH2.o /tmp/fileTxaQrb.o /tmp/fileqh3aE2.o \
            /tmp/fileYYijnB.o /tmp/file7xPbic.o /tmp/fileVsXNP1.o \
            /tmp/fileykpidV.o /tmp/file4eH2rC.o -L/usr/lib/mlton/targets/self \
            -lmlton -lgdtoa -lm -lgmp -m64 -Wl,-znoexecstack
     Link finished in 0.14 + 0.00 (0% GC)
  MLton finished in 46.39 + 7.31 (14% GC)

I checked the MLTon documentation but I didn't see any information relative to the static compilation :/

If someone knows how to do it it will help me a lot ! Thanks in advance,

Best Regards;


EDIT

On the Cluster, when I try to execute ./spartacus

./spartacus: error while loading shared libraries: 
libgmp.so.10: cannot open shared object file: No such file or directory

Solution

  • You need to compile using -link-opt '-static':

    mlton -verbose 3 \
          -codegen native \
          -link-opt '-static' \
          -output spartacus \
          src/spartacus.mlb