package for ghci

S.D.Mechveliani mechvel@math.botik.ru
Wed, 30 May 2001 16:00:58 +0400


To my questions on the package creation for  ghci -package 

>> ...
>> How should look a package for this?

Simon Marlow <simonmar@microsoft.com>  writes

> The "package" consists of libraries, .hi files, and a package
> specification.  Which bit did you mean?

I meant all the three + a whole story of its correct arrangement -
to illustrate it on the given example of a single module project.
But as you said, my scheme of action in mainly correct.
So, let us go further. 

>> Is it created manually or by        ghc -package-name ... ?
>> ...
>> For I have an impression that the ghc-5.00 User's guide cannot
>> help in this situation.

> The user's guide says, about -package-name:
>
>	This option is added to the command line when compiling a
>      module that is destined to be part of package foo. If this
>      flag is omitted then the default package Main is assumed.
>
> seems fairly clear to me... which part are you confused about?


I expected that the user would not need to 
  (1) move  .hi, .o  files manually to  /t/export,
      collecting them from all the project directories
  (2) archivate manually  *.o  to  .a  library,
  (maybe) (3) create manually the structure  Package {...}.

Note that the application project forces the user to do all this 
manually to install the project.

I hoped               -package-name --make   
would do (1) and (2).
This fragment of User's Guide does not reject such hope.


> Which parts of the documentation aren't being helpful to you?  
> [..]

It looks that a newbie would not find out the needed order of
action: 
  1. package specification,  2. ghc-pkg ...  3. ghc --make ...,
  4. moving files and archivating to library.
Does the Guide specify such order?
Is it clear from the Guide which of these points can be done
automatically?
Where it is explained how to create a library  .a  from  *.o  ?
A naive functional programmer would not know this, maybe, this is 
a system hacker's territory (?).

I may mistake, this is only my impression.


>> Then, after creating manually  /t/export/libHSfoo.a
>> and converting it by
>>                ld -r --whole-archive libHSfoo.a -o libHSfoo.o
>> [..]
>>
>> it still does not work.       ghci -package foo
>> yields
>>   Loading package foo ... can't find .o or .so/.DLL for: HSfoo
>>   (libHSfoo.so: cannot open shared object file: No such file


> It looks like there may be a problem with your package spec.  
> Could you list the contents of p.txt that you used to create the 
> package?


I would reproduce the whole (short) story.

-------------------------------------------------------
/home/mechvel/t/A.hs  
                      contains  module A where a = 'a'

  and is one file project to build a package  foo
  to reside in the directory
                             /home/mechvel/t/export/

/home/mechvel/u/Main.hs  

  imitates the user work with the package  foo.   It contains  
                    
  module Main where  import A
                     main = putStr ['b', a, '\n']

1. Apply    ghc-pkg -a < p.txt
   
  with  p.txt  containing

  Package {name            = "foo",
           import_dirs     = ["/home/mechvel/t/export" ],
           source_dirs     = [],
           library_dirs    = ["/home/mechvel/t/export" ],
           hs_libraries    = ["HSfoo"],
           extra_libraries = ["HSfoo"],
           include_dirs    = [],      c_includes      = [], 
           package_deps    = [],      extra_ghc_opts  = [],  
           extra_cc_opts   = [],      extra_ld_opts   = []
          }

2.  Test it with   ghc-pkg -l

3.  cd ~/t
    ghc -package-name foo --make A

4.  mv  *.hi *.o  export/
    cd export

5.  ar -q libHSfoo.a  *.o
    ld -r --whole-archive libHSdocon.a -o libHSdocon.o
-----------------------------------------------------------

  cd ~/t 
  ghci -package foo
  ...
  Loading package std ... linking ... done.
  Loading package foo ... ghc-5.00.1: can't find .o or .so/.DLL for: 
  HSfoo (libHSfoo.so: cannot open shared object file: 
  No such file or directory)


Regards,

-----------------
Serge Mechveliani
mechvel@botik.ru