MLton compile statically - compilation

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

You need to compile using -link-opt '-static':
mlton -verbose 3 \
-codegen native \
-link-opt '-static' \
-output spartacus \
src/spartacus.mlb

Related

Manually link two targets

I am trying to convert a (sloppy) Makefile into a CMakeLists.txt to better work with my IDE (CLion).
My Makefile is as follows:
all:
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -Os -g -m32 -I. -c -o bin/boot0.o boot/boot0/boot0.S
ld -nostdlib -m elf_i386 -N -e start -Ttext 0x7c00 -o bin/boot0.elf bin/boot0.o
objcopy -S -O binary bin/boot0.elf bin/boot0
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -Os -g -m32 -I. -c -o bin/boot1.o boot/boot1/boot1.S
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -Os -g -m32 -I. -c -o bin/boot1main.o boot/boot1/boot1main.c
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -Os -g -m32 -I. -c -o bin/boot1lib.o boot/boot1/boot1lib.c
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -Os -g -m32 -I. -c -o bin/exec_kernel.o boot/boot1/exec_kernel.S
ld -nostdlib -m elf_i386 -N -e start -Ttext 0xd7000 -o bin/boot1.elf bin/boot1.o bin/boot1main.o bin/boot1lib.o bin/exec_kernel.o
objcopy -S -O binary bin/boot1.elf bin/boot1
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -D_KERN_ -Ikern -Ikern/kern -I. -m32 -O0 -c -o bin/entry.o kern/init/entry.S
ld -o kernel -nostdlib -e start -m elf_i386 -Ttext=0x00100000 bin/entry.o -b binary
dd if=/dev/zero of=project0.img bs=512 count=256
parted -s project0.img "mktable msdos mkpart primary 63s -1s set 1 boot on"
dd if=bin/boot0 of=project0.img bs=446 count=1 conv=notrunc
dd if=bin/boo1 of=project0.img bs=512 count=62 seek=1 conv=notrunc
dd if=kern/init/kernel of=project0.img bs=512 seek=63 conv=notrunc
Mostly I am using make just to run the commands.
I am running into trouble with the fact that I have three different sets of linker flags (one each for boot0, boot1, and kern.)
Should I create separate CMakeLists.txt in each subdirectory (boot0, boot1, and kern) and then have a main one that runs each in turn and then handles the dd and parted usage, is there a better way to do this, or is CMake not an appropriate tool here?
Please have short-cuts for the compiler commands first. Then write the rule to create the first target on which the second target is dependent. Then since the first target is created; now use it to create the second target.

Unable to link find libraries when linking

When I link the .ld file using gcc I got the following error
/usr/bin/ld: cannot find -lreadline
collect2: error: ld returned 1 exit status
my run.sh scripts contains the following command
rm *.o *.bin *.iso
rm -rf isodir
assemble boot.s file
as --32 boot.s -o boot.o
linking the kernel with kernel.o and boot.o files
gcc -m32 -lunistd -Wno-unused-result -c kernelCheck.c -o kernel.o -std=gnu99 -ffreestanding -flto -O2 -Wall -Wextra -L/usr/lib -fno-exceptions
gcc -m32 -T linker.ld -o MoraWing.bin -ffreestanding -Wl,--build-id=none -O2 -nostdlib boot.o kernel.o -lgcc
grub-file --is-x86-multiboot MoraWing.bin
building the iso file
mkdir -p isodir/boot/grub
cp MoraWing.bin isodir/boot/MoraWing.bin
cp grub.cfg isodir/boot/grub/grub.cfg
grub-mkrescue -o MoraWing.iso ./isodir
run it in qemu
qemu-system-x86_64 -cdrom MoraWing.iso
You need to install libreadline-dev, or a similar package suitable for your system (you should also specify what your system is).

How to compile boost async_client.cpp

What is the correct command to compile this code?
http://www.boost.org/doc/libs/1_45_0/doc/html/boost_asio/example/http/client/async_client.cpp
I had installed boost library in /usr/include/boost
E.g.
clang++ -std=c++03 -Wall -pedantic -g -O2 async_client.cpp -o async_client -lboost_system -lboost_thread -lpthread
Assuming your system's packaged version of Boost (or pre-configured include & lib paths). To make use of your custom built Boost library tree in ~/custom/boost:
clang++ -std=c++03 -Wall -pedantic -g -O2 \
-isystem ~/custom/boost/ ~/custom/boost/libs/asio/example/cpp03/http/client/ \
async_client.cpp -o async_client \
-L ~/custom/boost/stage/lib/ -Wl,-rpath,/home/sehe/custom/boost/stage/lib \
-lboost_system -lboost_thread -lpthread
Replace clang++ by g++ at will.
-std=c++03 -Wall -pedantic -g -O2 only for expositional purposes.

Why aren't debugging symbols being added to my output file?

I am trying to compile a project to run on an ARM board that I have. To use the debugger, I have to put debugging symbols in the resulting .elf file.
I configured everything and ran my makefile, which produced the following results:
arm-elf-gcc -x assembler-with-cpp -c -mcpu=arm7tdmi-s -g -gdwarf-2 -Wa,-amhls=src/crt.lst src/crt.S -o src/crt.o
arm-elf-gcc -c -mcpu=arm7tdmi-s -O0 -g -gdwarf-2 -mthumb-interwork -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=src/main.lst -MD -MP -MF .dep/main.o.d -I . -I./inc src/main.c -o src/main.o
arm-elf-gcc -c -mcpu=arm7tdmi-s -O0 -g -gdwarf-2 -mthumb-interwork -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=library/md5.lst -MD -MP -MF .dep/md5.o.d -I . -I./inc library/md5.c -o library/md5.o
arm-elf-gcc -c -mcpu=arm7tdmi-s -O0 -g -gdwarf-2 -mthumb-interwork -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=library/bignum.lst -MD -MP -MF .dep/bignum.o.d -I . -I./inc library/bignum.c -o library/bignum.o
arm-elf-gcc ./src/crt.o ./src/main.o ./library/md5.o ./library/bignum.o -mcpu=arm7tdmi-s -g -nostartfiles -T./prj/LPC2138_flash.ld -Wl,-Map=testFLASH.map,--cref,--no-warn-mismatch -nostdlib -L. -Wl,-static -ffunction-sections -Wl,--gc-sections -Wl,-s -fdata-sections -lc -lg -lnosys -o testFLASH.elf
I have put in the -g flags, but when I try to find debugging symbols, I get only :
C:\Users\stkerr\Code\EclipseWorkspace\LibraryWork>objdump -g testFLASH.elf
testFLASH.elf: file format elf32-little
This is further confirmed when I try to open the .elf file in my debugger, I get an error about the file not having debugging symbols.
Can anyone point to an error in my arm-elf-gcc calls or a flag that I am missing?
After poking around a little more in the documentation, the -Wl,-s is the problem.
It strips all symbols from the resulting executable, including the debugging information.

Programming in Lua on OS X?

What can I use to program Lua script on Mac OS X? I'm looking for something that I can use to compile/interpret Lua script on OS X.
My preferred way:
brew install lua
Thanks, Max!
And if you need to know how to install Homebrew, see Link and:
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
The Lua source easily compiles with no changes on the mac. It will build lua (the interpreter which can act on a source script, a pre-compiled script or interactively) and luac which can be used to pre-compile source scripts.
From the lua.org website: http://luabinaries.luaforge.net/download.html. The ones you want are the darwin binaries (they say Mac OS X in the description).
My favorite way (from the shell):
sudo port install lua
I LOVE macports!
Here is my terminal session from compiling and installing Lua from source, basically following these directions. I already had Apple's Developer Tools installed, and /usr/local/bin was already in my PATH, so I was able to skip some of the more time-consuming and/or tedious steps in the directions.
$ cd ~/Downloads
$ tar -xf lua-5.1.4.tar
$ cd lua-5.1.4
$ make macosx
cd src && make macosx
make all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lapi.o lapi.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lcode.o lcode.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ldebug.o ldebug.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ldo.o ldo.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ldump.o ldump.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lfunc.o lfunc.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lgc.o lgc.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o llex.o llex.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lmem.o lmem.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lobject.o lobject.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lopcodes.o lopcodes.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lparser.o lparser.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lstate.o lstate.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lstring.o lstring.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ltable.o ltable.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ltm.o ltm.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lundump.o lundump.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lvm.o lvm.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lzio.o lzio.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lauxlib.o lauxlib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lbaselib.o lbaselib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ldblib.o ldblib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o liolib.o liolib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lmathlib.o lmathlib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o loslib.o loslib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ltablib.o ltablib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lstrlib.o lstrlib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o loadlib.o loadlib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o linit.o linit.c
ar rcu liblua.a lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o lstrlib.o loadlib.o linit.o
ranlib liblua.a
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lua.o lua.c
gcc -o lua lua.o liblua.a -lm -lreadline
gcc -O2 -Wall -DLUA_USE_LINUX -c -o luac.o luac.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o print.o print.c
gcc -o luac luac.o print.o liblua.a -lm -lreadline
$ make test
src/lua test/hello.lua
Hello world, from Lua 5.1!
$ sudo make install INSTALL_TOP=/usr/local
Password:
cd src && mkdir -p /usr/local/bin /usr/local/include /usr/local/lib /usr/local/man/man1 /usr/local/share/lua/5.1 /usr/local/lib/lua/5.1
cd src && install -p -m 0755 lua luac /usr/local/bin
cd src && install -p -m 0644 lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp /usr/local/include
cd src && install -p -m 0644 liblua.a /usr/local/lib
cd doc && install -p -m 0644 lua.1 luac.1 /usr/local/man/man1
$ lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> print "Hi"
Hi
> = 2 + 3
5
> ^c
$ cd test
$ lua factorial.lua
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
11! = 39916800
12! = 479001600
13! = 6227020800
14! = 87178291200
15! = 1307674368000
16! = 20922789888000
If you don't want to compile your own Lua binaries, you can try ZeroBrane Studio Lua IDE, which comes packaged as a .dmg file for OSX. It's an IDE that allows you to edit and debug your Lua scripts. If you are just starting with Lua, it also includes 50+ examples and demo scripts, as well as integrated instructions on running them, so you won't be facing an empty screen not knowing where to start.
I just recently found Rudix—a maintained collection of precompiled Unix software for Mac.
While I'm sure you've already figured out a way of installing Lua, I came across your question by Googling the same thing. For anyone that's interested, here's the link to a recent Lua 5.1.4 dmg.

Resources