www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Library Linkage Keyword?

reply "Garett Bass" <gtbass studiotekne.com> writes:
I would like to specify linkage to static libraries within D source files.
I think this could be particularly handy for multiplatform applications and
applications that link to a large number of static libraries.  The libraries
could be specified whenever needed within the code, even within version
blocks where different libraries are used to acheive the same result in each
version.

I'm imagining a syntax similar to import:

// graphics.d

version (Windows)
{
    link gdi32;

    // exports and code referencing gdi32.lib methods
}

version (Linux)
{
    link Xlib;

    // exports and code referencing Xlib.lib methods
}

This would obviate the need to explicitly list all of the static library
dependencies when compiling, and would simplify and modularize the inclusion
of such dependencies.  I'm curious to hear what others in the community
think of this.
Aug 14 2004
next sibling parent reply J C Calvarese <jcc7 cox.net> writes:
Garett Bass wrote:
 I would like to specify linkage to static libraries within D source files.
 I think this could be particularly handy for multiplatform applications and
 applications that link to a large number of static libraries.  The libraries
 could be specified whenever needed within the code, even within version
 blocks where different libraries are used to acheive the same result in each
 version.
Sounds like a great idea to me.
 
 I'm imagining a syntax similar to import:
 
 // graphics.d
 
 version (Windows)
 {
     link gdi32;
Perhaps... link "gdi32"; or better yet, it should be a Predefined Pragma: pragma(link, "gdi32"); http://www.digitalmars.com/d/pragma.html Then the compiler-writer can ignore the info if he wishes, but there's still a standarized way to do this.
 
     // exports and code referencing gdi32.lib methods
 }
 
 version (Linux)
 {
     link Xlib;
 
     // exports and code referencing Xlib.lib methods
 }
 
 This would obviate the need to explicitly list all of the static library
 dependencies when compiling, and would simplify and modularize the inclusion
 of such dependencies.  I'm curious to hear what others in the community
 think of this.
-- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Aug 14 2004
parent "Garett Bass" <gtbass studiotekne.com> writes:
 I'm imagining a syntax similar to import:

 // graphics.d

 version (Windows)
 {
     link gdi32;
Perhaps... link "gdi32";
It was my goal to make the link keyword very similar to the import keyword, which does not use quotes to delimit the module name.
 or better yet, it should be a Predefined Pragma:
 pragma(link, "gdi32");

 http://www.digitalmars.com/d/pragma.html
I believe pragma can be used to suggest library linkage to some C/C++ compilers. However, I would prefer a keyword because it is a significantly more strictly defined compiler feature.
Aug 14 2004
prev sibling next sibling parent reply "antiAlias" <gblazzer corneleus.com> writes:
I think that's a great idea. It would work especially well for library code
that you use, but didn't write yourself. If that library depends upon some
other static library, this would save the programmer from having to
understand all those dependencies/requirements.

For example; if you use the Socket module (in Phobos) you have to remember
to link with wsock32.lib (or some equivalent). That's a pain that only gets
worse with more sophistication. If those dependencies can be communicated
from the compiler to the linker, then so much the better.



"Garett Bass" <gtbass studiotekne.com> wrote in message
news:cflrfp$2lsa$1 digitaldaemon.com...
 I would like to specify linkage to static libraries within D source files.
 I think this could be particularly handy for multiplatform applications
and
 applications that link to a large number of static libraries.  The
libraries
 could be specified whenever needed within the code, even within version
 blocks where different libraries are used to acheive the same result in
each
 version.

 I'm imagining a syntax similar to import:

 // graphics.d

 version (Windows)
 {
     link gdi32;

     // exports and code referencing gdi32.lib methods
 }

 version (Linux)
 {
     link Xlib;

     // exports and code referencing Xlib.lib methods
 }

 This would obviate the need to explicitly list all of the static library
 dependencies when compiling, and would simplify and modularize the
inclusion
 of such dependencies.  I'm curious to hear what others in the community
 think of this.
Aug 14 2004
parent Stephan Wienczny <Stephan Wienczny.de> writes:
antiAlias wrote:

 I think that's a great idea. It would work especially well for library code
 that you use, but didn't write yourself. If that library depends upon some
 other static library, this would save the programmer from having to
 understand all those dependencies/requirements.
 
 For example; if you use the Socket module (in Phobos) you have to remember
 to link with wsock32.lib (or some equivalent). That's a pain that only gets
 worse with more sophistication. If those dependencies can be communicated
 from the compiler to the linker, then so much the better.
 
It would be even better if you could use it to import the public interfaces of that lib... All you had to do is a standard way of defing such and put it inside. Stephan
Aug 14 2004
prev sibling next sibling parent Andy Friesen <andy ikagames.com> writes:
Garett Bass wrote:
 I would like to specify linkage to static libraries within D source files.
 I think this could be particularly handy for multiplatform applications and
 applications that link to a large number of static libraries.  The libraries
 could be specified whenever needed within the code, even within version
 blocks where different libraries are used to acheive the same result in each
 version.
 
 This would obviate the need to explicitly list all of the static library
 dependencies when compiling, and would simplify and modularize the inclusion
 of such dependencies.  I'm curious to hear what others in the community
 think of this.
Mixing the core language spec up with details about how compilers ought to interact with the surrounding platform is generally a bad idea. D.NET, for instance, had some issues reconciling DMD's directory-is-a-package policy with .NET's anything-you-want-is-a-namespace ideal. In the end, D.NET basically dumped the former completely. I agree that what you're asking for is an exceptionally useful thing to be able to do, though. A pragma would be extremely helpful for making library feel more atomic. Programmers could then add the library path with /I, and import. Done. No further compile script adjustment. Even better, if we could establish a convention where libraries are placed in a common place, (like, say, /dmd/src) even the /I phase could be skipped, reducing many build scripts to "dmd -of:my.exe *.d" -- andy
Aug 14 2004
prev sibling next sibling parent pragma <EricAnderton at yahoo dot com> <pragma_member pathlink.com> writes:
I love this idea.  

Right now, if the code has a dependency to a particular library, the only place
that copuling is maintained is in the build script.  Placing an explicit linkage
in the code (tunable by D's versioning system) would reduce build scripts down
to specifying the library path only.  That's a nice improvement indeed.

- Pragma

In article <cflrfp$2lsa$1 digitaldaemon.com>, Garett Bass says...
I would like to specify linkage to static libraries within D source files.
I think this could be particularly handy for multiplatform applications and
applications that link to a large number of static libraries.  The libraries
could be specified whenever needed within the code, even within version
blocks where different libraries are used to acheive the same result in each
version.

I'm imagining a syntax similar to import:

// graphics.d

version (Windows)
{
    link gdi32;

    // exports and code referencing gdi32.lib methods
}

version (Linux)
{
    link Xlib;

    // exports and code referencing Xlib.lib methods
}

This would obviate the need to explicitly list all of the static library
dependencies when compiling, and would simplify and modularize the inclusion
of such dependencies.  I'm curious to hear what others in the community
think of this.
Aug 14 2004
prev sibling parent Dawid =?UTF-8?B?Q2nEmcW8YXJraWV3aWN6?= <arael fov.pl> writes:
Garett Bass wrote:

 I would like to specify linkage to static libraries within D source files.
 I think this could be particularly handy for multiplatform applications
 (.....)
 inclusion
 of such dependencies.  I'm curious to hear what others in the community
 think of this.
Love it. -- Dawid Ciężarkiewicz | arael jid: arael fov.pl
Aug 15 2004