Unable to compile first Haskell Programme in VSCode - haskell

I just installed Stack GHCI and Visual Studio Code in my Windows. And I was trying to build and run the first simple Haskell putStrln programme, but with a big compile fail.
In VS Code terminal, I entered:
PS C:\Users\rmili\Documents> stack new TryHaskell
And a new folder "TryHaskell" was created, with the automatically created files "Lib.hs" and "Main.hs"
I tried to build and run the hs files. But I encountered the following errors:
In a new terminal, after I entered PS C:\Users\rmili\Documents\TryHaskell> stack build, this will result in the following error:
Error Messages:
"'C:\Users\rmili\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.4\bin\ghc-pkg.exe'
exited with an error:
ghc-pkg.exe: hLock: permission denied (Access is denied.)
)"
At the top of Main.hs and Lib.hs, the lines module Main where and module Lib both have curly lines underneath, with error message:
readCreateProcess: stack "exec" "ghc" "--" "-rtsopts=ignore" "-outputdir" "C:\\Users\\rmili\\AppData\\Local\\Temp\\hie-bios-98c9848bfed41b00" "-o" "C:\\Users\\rmili\\AppData\\Local\\hie-bios\\wrapper-4da94d68375fab32d2147da1837e9611.exe" "C:\\Users\\rmili\\AppData\\Local\\hie-bios\\wrapper-4da94d68375fab32d2147da1837e9611.hs" (exit 1): failedcompiler
Peek Problem (Alt+F8)
No quick fixes available
My GHCI directory looks fine, as shown below:
UPDATE: It seemed that antivirus is the problem for me, as whenever I tried to build a new hs file, there will be a pop up from Norton, saying data protector has blocked an action by Haskell server. After I asked Norton to exclude specifically such action, I could successfully compile and run my hs files.
However, the problem is that the curly lines under "module Main where" and "module Lib" remain. How can I remove the curly lines and its associated error messages as shown in point 2) above?

Welcome to Haskell!
Unfortunately, it seems Haskell on Windows has various "permission denied" bugs. (https://gitlab.haskell.org/ghc/ghc/-/issues/2924). I have no direct workaround to suggest, other than make sure all software is up-to-date, try different configurations, and try and build using ghc directly without stack.
Other things to try include making sure you are running as Administrator, and disabling your antivirus.

Related

Cannot build gtk4-rs based cargo, build fails with linking error "LINK : fatal error LNK1181: cannot open input file 'gobject-2.0.lib'"

I am trying to build a hello world project to see if gtk4-rs is working correctly, which always fails at creating the binaries. The rest of the build seems to fine (tried to run cargo clean and cargo check a couple of times, those do not produce any errors). My Cargo.toml just uses the version specified in the crate:
[dependencies]
gtk4 = "0.4.8"
My error is exactly the same as the one in this question, but running the cargo build in an admin powershell also fails with the same error.
I am on Win 11 and I've followed the installation instructions linked to by GTK themselves, https://github.com/wingtk/gvsbuild.
The linking error seems to indicate that gobject-2.0.lib is missing:
LINK : fatal error LNK1181: cannot open input file 'gobject-2.0.lib'
(Full error message (with redacted user directory) on Pastebin)
That file is found at c:\gtk-build\gtk\x64\release\lib, which is the default location for an installation produced by gvsbuild, as far as I can tell (I haven't messed with the files at all).
Both c:\gtk-build\gtk\x64\release\lib and c:\gtk-build\gtk\x64\release\bin are part of the path, restarting the machine did not seem to fix anything in this regard either.
I have not found anything close to helpful on the internet, so any pointers to what could be wrong here would be great.

How to include additional directories when configuring makefiles

I'm trying to compile geany-plugins-1.28. The debugger plugin (the only one I need) gives the error:
debug.c:53:21: fatal error: vte/vte.h: No such file or directory
#include <vte/vte.h>
Clearly it needs to know where this file is located to compile. I found the vte.h file in the src directory of the main program geany-1.28. When running
sudo ./configure cflags=-I/home/pi/Desktop/geany-1.28/src
I get the same error about the missing header later trying to compile the debugger plugin.
I ran
./configure --help
to get all the flag options. The output is here
How do I get this to configure correctly so that it compiles. I need to compile the debugger version 1.28 myself because apt only installs 1.24 which I think has a bug because it crashes when I run my code with the error:
close failed in file object destructor:
sys.execpthook is missing
lost sys.stderr
CFLAGS is case-sensitive environment variable, so you should set it before running configure, not try to pass it as a command line argument. This variant:
$ export CFLAGS=-I/home/pi/Desktop/geany-1.28/src
$ ./configure
leaves CFLAGS set for current shell until you leave it. While this:
$ CFLAGS=-I/home/pi/Desktop/geany-1.28/src ./configure
sets variable only for current command, i.e. configure.
Some other issues:
You do not need sudo to configure and make. It is also unnecessary for make install if you set PREFIX to a path you have privileges to write to.
Does plugin's build system also builds all it's dependencies? If not, you may face linker errors a bit later.
Update:
I have tried to build debugger plugin and got rid of your error. It seems that vte.h coming with Geany is it's intrinsic, while the plugin requires full-featured file from the library. So I just installed vte and vte-devel from repos. Nevertheless, I got some other unrelated errors coming from Glib. I will not continue my attempts to build all this right now. Hope my effort will be helpful at least a little.
As in this answer stated, vte.h is not the file you are looking for. Install libvte(-dev) package on your system and rerun configure.
Just for the record: vte.h on Geany is a dummy to allow Geany to kind of dynamical enable vte or disable it depending on vte is installed on the system or not.

Stack/Docker/IHaskell weird behaviour

I have a package with bunch of *.c and *.cpp files, listed inside c-sources field of *.cabal file. I need to include it inside a project with IHaskell and some other packages. Everything works fine, and builds without a problem. stack exec ghci works fine and I can import modules and execute any code. stack ghci though throws some weird errors, like this:
In file included from <command-line>:10:0:
/...blabla.../.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen/cabal_macros.h:157:0:
note: this is the location of the previous definition
#define CURRENT_PACKAGE_KEY "blabla"
^
And stack ghci inside my package complains about symbols exported from its C code. Another weird thing is that symbols depend on the order of exposed-modules in the configuration, so the error goes away if I put my *.hs module on top of others, but if I have two *.hs files importing from the same *.c file, it won't work! stack exec jupyter -- console --kernel haskell starts, but immediately throws unknown symbol error if I try to run some code from my package, always the same though.
I have a docker image based on fpco/stack-build, which just installs jupyter and other necessary stuff. I use lts-3.0 snapshot, if it's somehow relevant.
What is going on?
There have been a lot of improvements made recently to stack ghci, which is still mostly a work in progress. I'd recommend testing out stack master, and if the problem still exists opening a Github issue.

EclipseFP is searching for GHC and cannot find it

I have working Eclipse (Kepler Service Release 2) + EclipseFP (2.6.0) + Haskell Platform under Windows 8.1 x64.
In one moment after some cabal install, EclipseFP stopped working and showing me:
The program ghc version >=6.4 is required but it could not be found.
I have:
Uninstalled Haskell Platform
Deleted C:\Users\myuser\AppData\Roaming\cabal*
Deleted C:\Program Files (x86)\Haskell*
Install Haskell Platform 2013.2
Run Eclipse with my Haskell workspace
Try to build my project
It gave me this error about ghc and cannot build it.
EclipseFP configuration found all Haskell Helper executables. It found Cabal 1.16.0.2 and GHC 7.6.3 already. From command-line GHC and cabal are found and are working. "cabal build" is working on the project from command-line, too.
This message doesn't say almost anything! If I could see the path it is searching for GHC or where it get this path from...
EDIT:
Message from buildwrapper:
"C:\Users\home\AppData\Roaming\cabal\bin\buildwrapper.exe synchronize --force=false --tempfolder=.dist-buildwrapper --cabalpath=C:\Program Files (x86)\Haskell Platform\2013.2.0.0\lib\extralibs\bin\cabal.exe --cabalfile=D:\Project\haskell2\SomeGL\SomeGL.cabal --cabalflags= --logcabal=true
configuring because setup_config not present
"C:\Program Files (x86)\Haskell Platform\2013.2.0.0\lib\extralibs\bin\cabal.exe" "configure" "--verbose=1" "--user" "--enable-tests" "--enable-benchmarks" "--builddir=D:\Project\haskell2\SomeGL.dist-buildwrapper\dist"
cabal.exe: The program ghc version >=6.4 is required but it could not be found."
Calling exactly the last line from cmd.exe (as normal non-admin user) everything is working fine:
"C:\Program Files (x86)\Haskell Platform\2013.2.0.0\lib\extralibs\bin\cabal.exe" "configure" "--verbose=1" "--user" "--enable-tests" "--enable-benchmarks" "--builddir=D:\Project\haskell2\SomeGL\.dist-buildwrapper\dist"
EDIT:
To find the potential path environement that is used I tried to run GHCi console inside Eclipse and tried:
import System.Environment
x <- getEnvironment
filter (\ (a,_) -> a == "Path") x
and got something that is starting with:
[("Path","C:\Program Files (x86)\Haskell\bin;C:\Program Files
(x86)\Haskell Platform\2013.2.0.0\lib\extralibs\bin;C:\Program
Files (x86)\Haskell Platform\2013.2.0.0\bin;...")]
First folder is invalid, but Haskell Platform is valid and working.
Another thing I found. One of times I have run "Build All" command there was run Process in Eclipse with GHC and the path was:
Running executable C:\Program Files (x86)\Haskell
Platform\2013.2.0.0\bin\ghc.exe
I went to see this process details and it is run from the same user that is currently Eclipse run with. And the path is correct, but I still got the error:
The program ghc version >=6.4 is required but it could not be found.
Running from command-line still it is working. The program has errors, but only in command-line I see them.
Could someone help with finding this problem?
EDIT:
I found some interesting issue. Running "Build All" command is executing this command:
C:\Users\myuser\AppData\Roaming\cabal\bin\buildwrapper.exe synchronize
--force=false --tempfolder=.dist-buildwrapper --cabalpath=C:\Program Files (x86)\Haskell Platform\2013.2.0.0\lib\extralibs\bin\cabal.exe
--cabalfile=D:\haskell\SomeGL\SomeGL.cabal --cabalflags= --logcabal=true
Which run from command-line gives an error. The problem is that there are no quotes around cabalpath, because it has spaces in it. When I run it that way from command-line it works:
C:\Users\myuser\AppData\Roaming\cabal\bin\buildwrapper.exe synchronize --force=false --tempfolder=.dist-buildwrapper --cabalpath="C:\Program Files (x86)\Haskell Platform\2013.2.0.0\lib\extralibs\bin\cabal.exe" --cabalfile=D:\haskell\SomeGL\SomeGL.cabal --cabalflags= --logcabal=true
I think that all "--cabalfile" parameters should have quotes, because paths could have spaces in them. I still don't know if this is the problem under Eclipse.
I found the problem!
It is that EclipseFP 2.6.0 is using upper case "PATH" variable, but my Windows 8.1 use "Path" and programatically some kind it is possible to have valid two variables "PATH" and "Path" when executing BuildWrapper and Cabal. So something is messing up.
Workaround for this problem is if you rename from Control Panel | System | Environment variables for both User and System from "Path" to "PATH".
I hope this could be fixed in EclipseFP so it could in future work in any case.
Building your project means that under the scenes, cabal build is launched. If you activate the debugging mode in the Haskell helper executable preference page (show BuildWrapper responses), you should see the exact cabal build command being sent. It could be that the path used in Eclipse is different than the path used in the command line, check you eclipse shortcuts. EclipseFP can find the executables because it searches also in some well known folders on windows.
You can also take the current dev version of EclipseFP from github. It should now pass --with-ghc to cabal invocations to make sure the path detected in Eclipse is the one used.

Android NDK build gives make error 6

Can't get Eclipse to build my NDK/JNI project. Eclipse, or ndk-build from a command prompt, both give following output:
/cygdrive/c/android-ndk-r8b/build/core/setup-app.mk:75: recipe for target `clean-installed-binaries' failed
make: *** [clean-installed-binaries] Error 6
What is "Error 6"? I can't find any doc on that anywhere. Helpfully, it doesn't say what the problem is, just giving the cryptic error code.
I found setup-app.mk and tried inserting something to echo the command it was executing, which was simply removing some files. I copied and pasted it to the command prompt and it worked fine on its own:
rm -f ./libs/armeabi/lib*.so ./libs/armeabi-v7a/lib*.so ./libs/mips/lib*.so ./libs/x86/lib*.so
Also tried inserting a "whoami" and it matched a whoami directly from the command prompt, so it's not acting as a different user with different permissions or something.
Been stuck on this for days. Can anyone help?
Rob.
PS. I'm finding Eclipse/NDK/JNI almost impossible to work with. It only seems to work for a week or two before falling in a heap again, seemingly with no change from me. This one is now unusable until I fix this error. I also have it installed on another machine, which is now also completely broken for completely different reasons. How does anyone work in this environment?
It's no miracle the actual command works: the error message comes from the make itself, which failed to generate the appropriate command!
Now what could have happened: most likely, you have some paths with spaces. Make sure that neigher eclipse, cygwin, project, workspace, nor ndk have spaces in their root paths.
Maybe, there is some problem with PATH. I refer to the environment variable in three environments: windows native, cygwin, and eclipse. Could it be that make you actually run is different from what you expect?
Note that you do not need cygwin to build with NDK 7 and higher, simply use ndk-build.cmd.

Resources