Thread overview
Linking to C library [gdc/mac]
Jan 06, 2007
Graham MacDonald
Jan 06, 2007
Johan Granberg
Jan 07, 2007
Bradley Smith
Jan 07, 2007
Graham MacDonald
Jan 13, 2007
Graham MacDonald
Jan 13, 2007
Johan Granberg
Jan 13, 2007
Graham MacDonald
Jan 13, 2007
John Reimer
January 06, 2007
Apologies if this has been asked previously - I'm new to D and haven't seen the info anywhere.

I want to use a C library (glfw, probably others) from within my D code.  I want to link using gdc.  How can I do this?  Am I right in thinking I would have to create a D module (as described for dmd in http://www.digitalmars.com/d/htomodule.html)?

Thanks!

Graham
January 06, 2007
Graham MacDonald wrote:

> Apologies if this has been asked previously - I'm new to D and haven't seen the info anywhere.
> 
> I want to use a C library (glfw, probably others) from within my D code.
>   I want to link using gdc.  How can I do this?  Am I right in thinking
> I would have to create a D module (as described for dmd in
> http://www.digitalmars.com/d/htomodule.html)?
> 
> Thanks!
> 
> Graham

Firstly glfw has d bindings already created in the standard distribution.
Secondly you can call any c function by declaring it for
example "extern(C)int write(char*);".
If you intend to use only a small subset of a library this is simpler than
creating an entier d module. (a d module for linking with c is just some
extern(c) declarations of structs and functions and some glue code to
handle defines)
January 07, 2007
In addition to the d bindings mentioned previously, GLD is a D language port of the GLFW library. It can be obtained from http://dsource.org/projects/schooner. However, it has not been tested with gdc, only with the DMD compiler on Linux and Windows. It should work with gdc, but the build has not been configured for it yet.

  Bradley


Graham MacDonald wrote:
> Apologies if this has been asked previously - I'm new to D and haven't seen the info anywhere.
> 
> I want to use a C library (glfw, probably others) from within my D code.  I want to link using gdc.  How can I do this?  Am I right in thinking I would have to create a D module (as described for dmd in http://www.digitalmars.com/d/htomodule.html)?
> 
> Thanks!
> 
> Graham
January 07, 2007
Thanks guys - I took the code in the glfw package and made some minor changes to get it building on mac and it works a treat now.

g
January 13, 2007
I got glfw to link with my app, but I am having different problems with freetype.  I'm trying to statically link the latest version of freetype to my app.  I have some bindings I took from the derelict freetype binding, but have removed the dynamic linking/derelict library code.

The problem I'm having is that when I finally link my obj files, libraries & frameworks, I get an undefined symbol:
  __D8freetype2ft12__ModuleInfoZ

Can someone explain what I'm missing here?  I've linked with:
  gdc obj/*.o -g -o game -lglfw -lfreetype -framework Carbon -framework OpenGL -framework AGL

Seems ok to me, but I'm sure I've missed something.

Thanks in advance

Graham
January 13, 2007
Graham MacDonald wrote:

> I got glfw to link with my app, but I am having different problems with freetype.  I'm trying to statically link the latest version of freetype to my app.  I have some bindings I took from the derelict freetype binding, but have removed the dynamic linking/derelict library code.
> 
> The problem I'm having is that when I finally link my obj files,
> libraries & frameworks, I get an undefined symbol:
>    __D8freetype2ft12__ModuleInfoZ
> 
> Can someone explain what I'm missing here?  I've linked with:
>    gdc obj/*.o -g -o game -lglfw -lfreetype -framework Carbon -framework
> OpenGL -framework AGL
> 
> Seems ok to me, but I'm sure I've missed something.
> 
> Thanks in advance
> 
> Graham

Have you compiled the freetype binding and linked the resulting .o file in your app?
January 13, 2007
Johan Granberg wrote:
> Graham MacDonald wrote:
> 
>> I got glfw to link with my app, but I am having different problems with
>> freetype.  I'm trying to statically link the latest version of freetype
>> to my app.  I have some bindings I took from the derelict freetype
>> binding, but have removed the dynamic linking/derelict library code.
>>
>> The problem I'm having is that when I finally link my obj files,
>> libraries & frameworks, I get an undefined symbol:
>>    __D8freetype2ft12__ModuleInfoZ
>>
>> Can someone explain what I'm missing here?  I've linked with:
>>    gdc obj/*.o -g -o game -lglfw -lfreetype -framework Carbon -framework
>> OpenGL -framework AGL
>>
>> Seems ok to me, but I'm sure I've missed something.
>>
>> Thanks in advance
>>
>> Graham
> 
> Have you compiled the freetype binding and linked the resulting .o file in
> your app?

.....that's the one!  I didn't realise I have to compile the binding since I was importing it.

Thanks!

graham
January 13, 2007
On Sat, 13 Jan 2007 16:59:19 +0000, Graham MacDonald wrote:

> Johan Granberg wrote:
>> Graham MacDonald wrote:
>> 
>>> I got glfw to link with my app, but I am having different problems with freetype.  I'm trying to statically link the latest version of freetype to my app.  I have some bindings I took from the derelict freetype binding, but have removed the dynamic linking/derelict library code.
>>>
>>> The problem I'm having is that when I finally link my obj files,
>>> libraries & frameworks, I get an undefined symbol:
>>>    __D8freetype2ft12__ModuleInfoZ
>>>
>>> Can someone explain what I'm missing here?  I've linked with:
>>>    gdc obj/*.o -g -o game -lglfw -lfreetype -framework Carbon -framework
>>> OpenGL -framework AGL
>>>
>>> Seems ok to me, but I'm sure I've missed something.
>>>
>>> Thanks in advance
>>>
>>> Graham
>> 
>> Have you compiled the freetype binding and linked the resulting .o file in your app?
> 
> .....that's the one!  I didn't realise I have to compile the binding since I was importing it.
> 
> Thanks!
> 
> graham


You have to link these symbols in because they will be assigned pointers to the freetype functions at runtime (from the shared library).

If the the static import modules were used, meaning you are linking with a static lib, then you wouldn't have to link in the module.

-JJR