Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a program so that it doesn't require DLLs

How can I compile a (Haskell) program so that it doesn't require DLLs?

I wrote a program that uses GLUT and requires glut32.dll. I compiled it with ghc --make program.hs. Now I want to distribute my program, but I don't want it to require any DLLs (so I can just give the .exe to the users). I tried compiling with ghc -static --make program.hs but it didn't work, I still get "user error (unknown GLUT entry glutInit)".

How can I do this?

like image 325
Jerry Avatar asked Dec 05 '10 20:12

Jerry


2 Answers

This is only possible if GLUT provides a static version of the library (this could be named something like glut32s.lib but there's no requirement that they call it anything in particular).

The success of this approach will also depend on whether GHC allows linking with external static libraries at all. The man page for ghc indicates that -static applies only to the Haskell libraries, not other external libraries.

like image 89
Greg Hewgill Avatar answered Oct 04 '22 01:10

Greg Hewgill


Assuming you have static versions of the required C libraries, you can create a static Haskell executable with:

 ghc -O2 --make -static -optc-static -optl-static A.hs -fvia-C

which ensures both the Haskell components, and C components will be linked statically, via the C toolchain.

like image 30
Don Stewart Avatar answered Oct 04 '22 01:10

Don Stewart