<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<meta name="generator" content="Windows Mail 17.5.9600.20911">
<style><!--
html {
font-family:"Color Emoji", "Calibri", "Segoe UI", "Meiryo", "Microsoft YaHei UI", "Microsoft JhengHei UI", "Malgun Gothic", "sans-serif";
}
--></style><style data-externalstyle="true"><!--
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
}
p.MsoNormal, li.MsoNormal, div.MsoNormal {
margin:0in;
margin-bottom:.0001pt;
}
p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst, 
p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle, 
p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast {
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
line-height:115%;
}
--></style>
</head>
<body dir="ltr">
<div data-externalstyle="false" dir="ltr" style="font-family: 'Calibri', 'Segoe UI', 'Meiryo', 'Microsoft YaHei UI', 'Microsoft JhengHei UI', 'Malgun Gothic', 'sans-serif';font-size:12pt;">
<div>Hello Neil,</div>
<div><br>
</div>
<div>Sorry about the delay; I hadn't gotten around to seeing if I could reproduce it. Here is a working copy of the program which appears to work with GHC 7.10.2 on 64-bit Windows:</div>
<div><br>
</div>
<div><font face="Consolas">module Main where</font><br>
<font face="Consolas">import GHC</font><br>
<font face="Consolas">import GHC.Paths ( libdir )</font><br>
<font face="Consolas">import DynFlags</font><br>
<font face="Consolas">import SysTools</font></div>
<div><br>
</div>
<div><font face="Consolas">main = do</font><br>
<font face="Consolas">  defaultErrorHandler defaultFatalMessager defaultFlushOut $ do</font><br>
<font face="Consolas">    runGhc (Just libdir) $ do</font><br>
<font face="Consolas">            dflags <- getSessionDynFlags</font><br>
<font face="Consolas">            setSessionDynFlags (gopt_set dflags Opt_Static)</font><br>
<font face="Consolas">            target <- guessTarget "Test.hs" Nothing</font><br>
<font face="Consolas">            setTargets [target]</font><br>
<font face="Consolas">            load LoadAllTargets</font><br>
<br>
</div>
<div data-signatureblock="true">
<div>Here is how I tested it:<br>
</div>
<font size="1">
<p class="defaultFont"><font face="Consolas" style="font-size: 12pt;">stack ghc -- -package ghc -package ghc-paths --make Main.hs</font></p>
</font></div>
<div data-signatureblock="true">(after stack installing ghc-paths)
<div><br>
</div>
<div>Did you mean the error occurred when you did set Opt_Static? I can’t reproduce your specific error in that case either.</div>
<div><br>
</div>
<div>Cheers,</div>
<div>Edward</div>
<div><br>
</div>
<div>Sent from Windows Mail</div>
<div><br>
</div>
</div>
<div style="padding-top: 5px; border-top-color: rgb(229, 229, 229); border-top-width: 1px; border-top-style: solid;">
<div><font face=" 'Calibri', 'Segoe UI', 'Meiryo', 'Microsoft YaHei UI', 'Microsoft JhengHei UI', 'Malgun Gothic', 'sans-serif'" style="line-height: 15pt; letter-spacing: 0.02em; font-family: "Calibri", "Segoe UI", "Meiryo", "Microsoft YaHei UI", "Microsoft JhengHei UI", "Malgun Gothic", "sans-serif"; font-size: 12pt;"><b>From:</b> <a href="mailto:ndmitchell@gmail.com" target="_parent">Neil
 Mitchell</a><br>
<b>Sent:</b> ýMondayý, ýAugustý ý24ý, ý2015 ý12ý:ý42ý ýAM<br>
<b>To:</b> <a href="mailto:ezyang@mit.edu" target="_parent">Edward Z Yang</a><br>
<b>Cc:</b> <a href="mailto:ghc-devs@haskell.org" target="_parent">ghc-devs@haskell.org</a></font></div>
</div>
<div><br>
</div>
<div dir="">
<div id="readingPaneBodyContent">Thanks Edward, that fixed the issue with GHC 7.8.3. While trying to<br>
replicate with 7.10.2 to submit a bug report, I got a different error,<br>
even with your fix included:<br>
<br>
C:\Users\NDMIT_~1\AppData\Local\Temp\ghc2428_1\ghc_4.o:ghc_3.c:(.text+0x55):<br>
undefined reference to `ZCMain_main_closure'<br>
<br>
Doing another diff of the command lines, I see ghc --make includes<br>
"Test.o" on the Link line, but the API doesn't.<br>
<br>
Thanks, Neil<br>
<br>
<br>
On Mon, Aug 24, 2015 at 12:00 AM, Edward Z. Yang <ezyang@mit.edu> wrote:<br>
> The problem is that the default code is trying to build a dynamically<br>
> linked executable, but the Windows distributions don't come with dlls<br>
> by default.<br>
><br>
> Why doesn't the GHC API code pick this up?  Based on snooping<br>
> ghc/Main.hs, it's probably because you need to call parseDynamicFlags*<br>
> which will call updateWays which will turn off -dynamic-too if the<br>
> platform doesn't support it.<br>
><br>
> GHC bug? Absolutely! Please file a ticket.<br>
><br>
> Edward<br>
><br>
> Excerpts from Neil Mitchell's message of 2015-08-23 05:43:28 -0700:<br>
>> Hi,<br>
>><br>
>> Is this the right place for GHC API queries? If not, is there anywhere better?<br>
>><br>
>> I want to compile a Haskell module, much like `ghc --make` or `ghc -c`<br>
>> does. The sample code on the Haskell wiki<br>
>> (https://wiki.haskell.org/GHC/As_a_library#A_Simple_Example),<br>
>> StackOverflow (http://stackoverflow.com/a/5631338/160673) and in GHC<br>
>> API slides (http://sneezy.cs.nott.ac.uk/fplunch/weblog/wp-content/uploads/2008/12/ghc-api-slidesnotes.pdf)<br>
>> says:<br>
>><br>
>>     import GHC<br>
>>     import GHC.Paths ( libdir )<br>
>>     import DynFlags<br>
>><br>
>>     main =<br>
>>         defaultErrorHandler defaultFatalMessager defaultFlushOut $ do<br>
>>           runGhc (Just libdir) $ do<br>
>>             dflags <- getSessionDynFlags<br>
>>             setSessionDynFlags dflags<br>
>>             target <- guessTarget "Test.hs" Nothing<br>
>>             setTargets [target]<br>
>>             load LoadAllTargets<br>
>><br>
>> However, given a `Test.hs` file with the contents `main = print 1`, I<br>
>> get the error:<br>
>><br>
>>     C:/Program Files (x86)/MinGHC-7.8.3/ghc-7.8.3/mingw/bin/ld.exe:<br>
>> cannot find -lHSbase-4.7.0.1-ghc7.8.3<br>
>>     C:/Program Files (x86)/MinGHC-7.8.3/ghc-7.8.3/mingw/bin/ld.exe:<br>
>> cannot find -lHSinteger-gmp-0.5.1.0-ghc7.8.3<br>
>>     C:/Program Files (x86)/MinGHC-7.8.3/ghc-7.8.3/mingw/bin/ld.exe:<br>
>> cannot find -lHSghc-prim-0.3.1.0-ghc7.8.3<br>
>>     C:/Program Files (x86)/MinGHC-7.8.3/ghc-7.8.3/mingw/bin/ld.exe:<br>
>> cannot find -lHSrts-ghc7.8.3<br>
>>     C:/Program Files (x86)/MinGHC-7.8.3/ghc-7.8.3/mingw/bin/ld.exe:<br>
>> cannot find -lffi-6<br>
>>     collect2: ld returned 1 exit status<br>
>><br>
>> Has the recipe changed?<br>
>><br>
>> By turning up the verbosity, I was able to compare the command line<br>
>> passed to the linker. The failing GHC API call contains:<br>
>><br>
>>     "-lHSbase-4.7.0.1-ghc7.8.3" "-lHSinteger-gmp-0.5.1.0-ghc7.8.3"<br>
>> "-lHSghc-prim-0.3.1.0-ghc7.8.3" "-lHSrts-ghc7.8.3" "-lffi-6"<br>
>><br>
>> While the succeeding ghc --make contains:<br>
>><br>
>>     "-lHSbase-4.7.0.1" "-lHSinteger-gmp-0.5.1.0"<br>
>> "-lHSghc-prim-0.3.1.0" "-lHSrts" "-lCffi-6"<br>
>><br>
>> Should I be getting DynFlags differently to influence those link variables?<br>
>><br>
>> Thanks, Neil<br>
</div>
</div>
</div>
</body>
</html>