Stop! Tickets are now managed at GitHub.

Please enter new tickets, and find and edit existing tickets there:


Ticket #136 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

Windows error: "ghci: Unable to locate ghc.exe"

Reported by: mcandre Owned by: refold
Priority: major Milestone: 2010.2.0.0
Component: Windows installer Keywords:
Cc:

Description

Specs

Haskell Platform 2010.2.0.0

MS Windows 7 Professional x64

Problem

1. Open Command Prompt.

2. Enter ghci.

3. An error is displayed:

ghci: Unable to locate ghc.exe

Attempted Solution

Added C:\Program Files (x86)\Haskell Platform\2010.2.0.0\bin to PATH.

Solution did nothing to alleviate the problem.

Change History

Changed 4 years ago by refold

  • status changed from new to closed
  • resolution set to worksforme

Can't reproduce on XP x64.

Changed 4 years ago by mcandre

  • status changed from closed to reopened
  • resolution worksforme deleted

Look closely: I specified that I am using Windows 7, not XP. So you can't reproduce the issue unless you are also using Windows 7.

Changed 4 years ago by refold

Does this happen with the official GHC installer?

Changed 4 years ago by mcandre

I don't know. I used the current Haskell Platform installer.

Changed 4 years ago by refold

Can you uninstall Haskell Platform, install GHC 6.12.3 with the official installer and check if you can reproduce this bug? I don't have access to a Win7 machine currently.

Changed 4 years ago by refold

  • milestone set to 2010.2.0.0

Changed 4 years ago by mcandre

Yes, when I install using the official GHC 6.12.3 installer, I can use GHCi.

C:\Users\andrew\Desktop>ghci
GHCi, version 6.12.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude>

Changed 4 years ago by refold

Now that's weird. Looking at ghci.c, there are two calls that can give us this error: SearchPath? and GetShortPathName?. I'm suspecting the latter. Maybe this has something to do with spaces in the path? Given that GHC is installed to C:\ghc by default, what happens if you install HP to C:\hp2010?

Changed 4 years ago by mcandre

If I install Haskell Platform in C:\hp2010\, then GHCi works just fine. :)

I suggest putting quotes around the installation path in the installer.

Thanks, bud!

Changed 4 years ago by refold

I suggest putting quotes around the installation path in the installer.

Why do you think it will help? It was your original attempted solution, and it didn't work. The $PLATFORMDIR/bin is added to PATH, the problem is that the call to GetShortPathName in ghci fails on Win7 for some reason. I filed a ticket on the GHC bug tracker.

Changed 4 years ago by mcandre

It was NOT my attempted solution. My attempted solution was to manually create the correct variable within $PATH. My assumption was that somewhere within the Haskell Platform installer, a path such as "C:\Program Files\" instead of "\"C:\Program Files\"" is used. As a programmer, I've noticed that omitting these quotes often causes such problems.

I'm glad to hear that you've deduced the problem to be GetShortPathName?, which is far more specific than my guess.

Changed 4 years ago by refold

My attempted solution was to manually create the correct variable within $PATH.

That's what I meant - the failure's still there regardless of what is in $PATH, so something must be wrong with ghci.

I guess we'll have to wait for the reaction from GHC HQ. Or you can try to fix ghci.c and send GHC devs a patch.

Changed 4 years ago by mcandre

I downloaded ghci.c. There are only two entry paths to print the Unable to locate ghc.exe error message: lines 81-90 and lines 92-98.

  /* Locate the binary we want to start up */
  if ( !SearchPath(NULL,
		   BINARY_NAME,
		   NULL,
		   dwSize,
		   (char*)binPath,
		   &szEnd) ) {
    errmsg1("%s: Unable to locate ghc.exe", argv[0]);
    return 1;
  }
  
  dwSize = MAX_PATH;
  /* Turn the path into short form - LFN form causes problems
     when passed in argv[0]. */
  if ( !(GetShortPathName(binPath, binPathShort, dwSize)) ) {
    errmsg1("%s: Unable to locate ghc.exe", argv[0]);
    return 1;
  }

There appears to be an inconsistency in the code. SearchPath on line 86 casts binPath to a character pointer. Strangely, GetShortPathName on line 95 does not.

According to Microsoft documentation, both functions should use LPCTSTRs; in other words, TCHARs. If I'm wrong, then both should use char pointers. Either way, both should be passing the same types. But they're not.

If the wrong type is being passed to one of these functions, then the functions may return NULL, which would result in the error being printed.

Is any particular compiler used to create ghci.exe? I'm not sure if I should use Cygwin, MinGW, Visual Studio, or some other compilation system.

Changed 4 years ago by mcandre

I can compile ghci.c with MinGW. But it complains that I should have compiled using a wrapper:

C:\Users\andrew\Desktop\ghci test>ghci.exe
GHCi, version 6.12.3: http://www.haskell.org/ghc/  :? for help
: panic! (the 'impossible' happened)
  (GHC version 6.12.3 for i386-unknown-mingw32):
        can't decompose ghc.exe path: "C:\\Users\\andrew\\Desktop\\GHCITE~1\\ghc
.exe"

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

In ghci.c, a comment says to compile with MinGW as follows:

gcc -o ghci.exe ghciwrap.c

Where is ghciwrap.c? It's not in the same directory as ghci.c. Is the file created at compile time by make?

Changed 4 years ago by refold

I was able to succesfully compile ghci.c with gcc on XP:

$ gcc ghci.c -o ghci.exe

$ ./ghci.exe
WARNING: GHCi invoked via 'ghci.exe' in *nix-like shells (cygwin-bash, in partic
ular)
         doesn't handle Ctrl-C well; use the 'ghcii.sh' shell wrapper instead
GHCi, version 6.12.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.

I think that ghciwrap.c is the old name for ghci.c and the comment just wasn't updated.

Try commenting out this part:

  /* Turn the path into short form - LFN form causes problems
     when passed in argv[0]. */
  if ( !(GetShortPathName(binPath, binPathShort, dwSize)) ) {
    errmsg1("%s: Unable to locate ghc.exe", argv[0]);
    return 1;
  }

and see what happens.

Changed 4 years ago by mcandre

  • status changed from reopened to closed
  • resolution set to worksforme

That fixed it!

C:\Users\andrew\Desktop\ghci test>ghci
GHCi, version 6.12.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude>
Leaving GHCi.

ghci-space.patch

The resulting ghci.exe works with both GHC and Haskell Platform on my system.

Specs once more:

  • GHC 6.12.3
  • Haskell Platform 2010.2.0.0
  • MS Windows 7 Professional x64

Now GHCi works with default install location:

C:\Program Files (x86)\Haskell Platform\2010.2.0.0

Changed 4 years ago by refold

Great! I've updated the GHC ticket, now we have to wait for GHC devs to review the patch.

Changed 4 years ago by refold

  • status changed from closed to reopened
  • resolution worksforme deleted

Changed 4 years ago by refold

  • status changed from reopened to closed
  • resolution set to fixed

According to Ian Lynagh, this was fixed in GHC HEAD.

Note: See TracTickets for help on using tickets.