If statically linking in the Makefile, we need to make sure that our
putchard symbol/function doesn't get stripped out, as GHC passes the
-dead_strip flag to the linker to remove any unused functions. Since
nothing directly calls putchard in our program, it will get stripped out
unless we specify that we want to export it. We can use an export list
to indicate that we still want the symbol. (On Linux, you might need to
remove the underscore from _putchard. )
stdlib.dylib: stdlib.c
clang -shared $< -o $@
stdlib.dylib: stdlib.c
clang -shared $< -o $@
+
+# for statically linking the stdlib:
+# make sure to change in Main.hs
+# loadLibraryPermanently (Just "stdlib.dylib")
+# to
+# loadLibraryPermanently Nothing
+stdlib.o: stdlib.c
+ clang -c $< -o $@
+
+Main: Main.hs stdlib.o
+ ghc $^ -o $@ -optl -Wl,-exported_symbols_list,stdlib.syms \
+ -no-keep-hi-files -no-keep-o-files