I'm trying to compile a Haskell program which takes a string from a txt file and adds it at the end of another string, in a different txt. file. But when I try to compile it in my terminal I get following error message:
C:\Users\Benni>ghc-9.2.3.exe vonquellezumziel1.hs quelle.txt ziel.txt
Loaded package environment from C:\Users\Benni\AppData\Roaming\ghc\x86_64-mingw32-9.2.3\environments\default
Linking vonquellezumziel1.exe ...
C://tools//ghc-9.2.3//mingw//bin/ld.exe:quelle.txt: file format not recognized; treating as linker script
C://tools//ghc-9.2.3//mingw//bin/ld.exe:quelle.txt:0: syntax error
collect2.exe: error: ld returned 1 exit status
`gcc.exe' failed in phase `Linker'. (Exit code: 1)
that's the Haskell code which I got from my Prof.:
−− vonquellezumziel1.hs
importSystem.IO
main :: IO()
main = do
leseGriff <- openFile "quelle.txt" ReadMode
inhalt <- hGetContents leseGriff
schreibGriff <- openFile "ziel.txt" AppendMode
hPutStr schreibGriff inhalt
hClose leseGriff
hClose schreibGriff
the variables are named in German so I hope that's not a problem.
the way I'm using to compile the programs is by using: ghc-9.2.3.exe filename
all the answers I found were for C or C++, but I'm using Haskell so I don't really know what to do.
Thanks for the help.
You seem to be confusing compilation and execution of the compiled program. When you run
> ghc-9.2.3.exe vonquellezumziel1.hs quelle.txt ziel.txt
you are telling the compiler to take the three files vonquellezumziel1.hs
, quelle.txt
and ziel.txt
, and treat them as haskell files, and compile them to a binary executable.
What you actually want to do is first compile the program
> ghc-9.2.3.exe vonquellezumziel1.hs
Then run it
> ./vonquellezumziel1
The program does not take any command line arguments, it just reads and write files from disk in the current directory.
The code you pasted here looks like the formatting is broken, I believe the file should actually look like:
import System.IO
main :: IO()
main = do
leseGriff <- openFile "quelle.txt" ReadMode
inhalt <- hGetContents leseGriff
schreibGriff <- openFile "ziel.txt" AppendMode
hPutStr schreibGriff inhalt
hClose leseGriff
hClose schreibGriff
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.