ghc - force library search order

Simon Marlow marlowsd at gmail.com
Tue Jun 2 06:43:05 EDT 2009


On 02/06/2009 00:30, John Lask wrote:
> I hav a module that depends upon (binds to) the microsoft uuid.lib
> (libuuid.a) this is a static library which exports some labels such as
> IID_IPersistFile. I was playing around with trying to get it to work
> both with normal compiling via ghc and to dynamically load in ghci. As
> we know, ghci can't load static libraries and so was not able to resolve
> the linkage. I therefore decided to directly incorporate the objects of
> (libuuid.a) into the haskell .a and ghci .o file (ghci) . To do this I
> needed to ject --whole-archive libuuid.a --no-whole-archive (or
> alternatively the list of objects) into the link command at an
> appropriate point to enable the resolution of the linkage.
>
> I have achieved my goal but only by constructing the list of objects to
> link entirely manually, constructing both the .a and .o for the haskell
> library manually. I am not satisfied with this solution as it is fragile
> wrt changes in the module structure of the library I have constructed.

Right, GHCi doesn't work very well with static libraries.

You can extract the contents of libuuid.a into a single .o file, and 
link this in - it sounds like that's what you're doing.  In order to be 
able to use this without manual hackery, you will need to construct a 
Haskell package that only tries to link libuuid.a when in batch-linking 
mode (not GHCi).  I think you can do this by given an empty 
extra-ghci-libraries field.  And then you'll need to add uuid.o to the 
command line when starting GHCi.

Cheers,
	Simon


>
> jvl
>
> ----- Original Message ----- From: "Simon Marlow" <marlowsd at gmail.com>
> To: "John Lask" <jvlask at hotmail.com>
> Cc: <glasgow-haskell-users at haskell.org>
> Sent: Monday, June 01, 2009 9:15 PM
> Subject: Re: ghc - force library search order
>
>
>> On 29/05/2009 15:19, John Lask wrote:
>>>
>>> ----- Original Message ----- From: "Duncan Coutts"
>>> <duncan.coutts at worc.ox.ac.uk>
>>> To: "John Lask" <jvlask at hotmail.com>
>>> Sent: Friday, May 29, 2009 8:09 PM
>>> Subject: Re: [Haskell-cafe] ghc - force library search order
>>>
>>>
>>>> On Fri, 2009-05-29 at 18:08 +1000, John Lask wrote:
>>>>> I need to force a library to be searched for unresolved symbols after
>>>>> all
>>>>> other libraries have been searched, and I would rather not resort to
>>>>> constructing the linker command line directly. Is there a way to do
>>>>> this?
>>>>>
>>>>> i.e. I want for example -lfoo to appear after all other haskell
>>>>> libraries
>>>>> and before system libraries (for example -lmsvcrt) once ghc has
>>>>> constructed
>>>>> the link command. i.e. how is it possible to coerce ghc into
>>>>> respecting
>>>>> dependencies between the libraries. GHC does a good job in general
>>>>> with
>>>>> native libraries, but there are allways corner cases.
>>>>>
>>>>> I have a feeling this is not possible, but it dosn't hurt to ask.
>>
>> No, there's currently no way to inject flags that come *after* the
>> linker flags for the packages on the linker command line.
>>
>> It might help if you describe at a higher level what it is you're
>> trying to do. There might be a better way to achieve it.
>>
>> Cheers,
>> Simon
>>
>



More information about the Glasgow-haskell-users mailing list