can run in ghci but can't compile.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

can run in ghci but can't compile.

Anand Mitra
Hi,

I can run the following program in the interpreter ghci but can't compile
it.

The program I am trying to compile is a simple copy using the lazy
bytestrings. I have been working out exercises from Real World haskell and I
was benchmarking this version which is supposed to be optimum.

,----
| import qualified  System  as S
| import qualified Data.ByteString.Lazy as L
|
| main = do
|   [from, to ] <- S.getArgs
|   file <- L.readFile from
|   L.writeFile to file
`----

While trying to compile this i get the following errors.

,----
| mitra@ravan:~/laptop/haskell/learn$ /opt/ghc-6.10.1/bin/ghc cp.hs
| cp.o: In function `sB1_info':
| (.text+0xab): undefined reference to
`bytestringzm0zi9zi1zi4_DataziByteStringziLazzy_writeFile_closure'
| cp.o: In function `sAW_info':
| (.text+0xe1): undefined reference to
`bytestringzm0zi9zi1zi4_DataziByteStringziLazzy_readFile_closure'
| cp.o: In function `sB5_info':
| (.text+0x30f): undefined reference to
`__stginit_bytestringzm0zi9zi1zi4_DataziByteStringziLazzy_'
| cp.o: In function `sB5_srt':
| (.data+0x4): undefined reference to
`bytestringzm0zi9zi1zi4_DataziByteStringziLazzy_readFile_closure'
| cp.o: In function `sB5_srt':
| (.data+0x8): undefined reference to
`bytestringzm0zi9zi1zi4_DataziByteStringziLazzy_writeFile_closure'
| collect2: ld returned 1 exit status
| mitra@ravan:~/laptop/haskell/learn$  rm cp.o
| mitra@ravan:~/laptop/haskell/learn$ /opt/ghc-6.10.1/bin/ghc cp.hs
| cp.o: In function `sB0_info':
| (.text+0xab): undefined reference to
`bytestringzm0zi9zi1zi4_DataziByteStringziLazzy_writeFile_closure'
| cp.o: In function `sAV_info':
`----

But this program is not syntactically or otherwise flawed since I can run it
under ghci.

,----
| mitra@ravan:~/laptop/haskell/learn$ /opt/ghc-6.10.1/bin/ghci
| GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
| Loading package ghc-prim ... linking ... done.
| Loading package integer ... linking ... done.
| Loading package base ... linking ... done.
| Prelude> :l cp.hs
| Ok, modules loaded: Main.
| Prelude Main> :main /etc/passwd /tmp/xyz
| Loading package bytestring-0.9.1.4 ... linking ... done.
| Loading package unix-2.3.1.0 ... linking ... done.
| Loading package filepath-1.1.0.1 ... linking ... done.
| Loading package old-locale-1.0.0.1 ... linking ... done.
| Loading package old-time-1.0.0.1 ... linking ... done.
| Loading package directory-1.0.0.2 ... linking ... done.
| Loading package process-1.0.1.0 ... linking ... done.
| Loading package syb ... linking ... done.
| Loading package array-0.2.0.0 ... linking ... done.
| Loading package random-1.0.0.1 ... linking ... done.
| Loading package haskell98 ... linking ... done.
| Prelude Main>
`----

Since I suspect that this might be a problem with the way I have installed
gch-6.10.1 I will explain how I have installed it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090330/ba84cbd3/attachment.htm
Reply | Threaded
Open this post in threaded view
|

can run in ghci but can't compile.

Brandon S Allbery KF8NH
Skipped content of type multipart/alternative-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/beginners/attachments/20090330/58cb6211/PGP.bin
Reply | Threaded
Open this post in threaded view
|

can run in ghci but can't compile.

Anand Mitra
That does the job, Thanks !!

Just to understand what is happening under the hood I tried to resolve this
to the exact steps. The problem I faced seems to be equivalent of missing a
-L and -l in gcc. Looking at the man for ghc I did find it had the -l and -L
flags. Now I had to find the path and the name of the library. Did a find
over the location I have installed ghc I was able to short list the likely
candidates.

,----
| find /opt/ghc-6.10.1/ -type f |grep \\.a$
| ....
|
/opt/ghc-6.10.1/lib/ghc-6.10.1/bytestring-0.9.1.4/libHSbytestring-0.9.1.4.a
|
/opt/ghc-6.10.1/lib/ghc-6.10.1/bytestring-0.9.1.4/libHSbytestring-0.9.1.4_p.a
| ....
`----

and as expected adding the -l and -L in the ghc command line does the trick.

/opt/ghc-6.10.1/bin/ghc -L/opt/ghc-6.10.1/lib/ghc-6.10.1/bytestring-0.9.1.4/
-lHSbytestring-0.9.1.4 cp.hs

regards
--
Anand Mitra

On Mon, Mar 30, 2009 at 10:45 PM, Brandon S. Allbery KF8NH <
[hidden email]> wrote:

> On 2009 Mar 30, at 13:12, Anand Mitra wrote:
>
> ,----
> | mitra@ravan:~/laptop/haskell/learn$ /opt/ghc-6.10.1/bin/ghc cp.hs
> | cp.o: In function `sB1_info':
> | (.text+0xab): undefined reference to
> `bytestringzm0zi9zi1zi4_DataziByteStringziLazzy_writeFile_closure'
> | cp.o: In function `sAW_info':
>
>
> Use "ghc --make".  ghci does this automatically.
>
> --
> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [hidden email]
> system administrator [openafs,heimdal,too many hats] [hidden email]
> electrical and computer engineering, carnegie mellon university    KF8NH
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090330/d84382e8/attachment-0001.htm
Reply | Threaded
Open this post in threaded view
|

can run in ghci but can't compile.

Daniel Fischer-4
Am Montag 30 M?rz 2009 19:54:28 schrieb Anand Mitra:

> That does the job, Thanks !!
>
> Just to understand what is happening under the hood I tried to resolve this
> to the exact steps. The problem I faced seems to be equivalent of missing a
> -L and -l in gcc. Looking at the man for ghc I did find it had the -l and
> -L flags. Now I had to find the path and the name of the library. Did a
> find over the location I have installed ghc I was able to short list the
> likely candidates.
>
> ,----
>
> | find /opt/ghc-6.10.1/ -type f |grep \\.a$
> | ....
>
> /opt/ghc-6.10.1/lib/ghc-6.10.1/bytestring-0.9.1.4/libHSbytestring-0.9.1.4.a
>
> /opt/ghc-6.10.1/lib/ghc-6.10.1/bytestring-0.9.1.4/libHSbytestring-0.9.1.4_p
>.a
>
> | ....
>
> `----
>
> and as expected adding the -l and -L in the ghc command line does the
> trick.
>
> /opt/ghc-6.10.1/bin/ghc
> -L/opt/ghc-6.10.1/lib/ghc-6.10.1/bytestring-0.9.1.4/ -lHSbytestring-0.9.1.4
> cp.hs
>
> regards

Or, simpler:

ghc -package bytestring -o anfile anand.hs

but I strongly recommend using --make for every compilation unless you know
that you really do *not* want it.