Library linking (request)

Jeremy Jeremy_member at pathlink.com
Mon Feb 27 19:44:55 PST 2006


In article <du03ss$2ugm$1 at digitaldaemon.com>, Jarrett Billingsley says...
>
>"Jeremy" <Jeremy_member at pathlink.com> wrote in message 
>news:du03ir$2u1d$1 at digitaldaemon.com...
>> Can there be something as simple as 'importlib (<type>) "<filename>"' in 
>> the
>> code? Say:
>>
>> importlib (dll) "alleg40.dll";
>> importlib (a) "libusb.a";
>
>Well, it's not _quite_ what you want, but it's better than nothing:
>
>pragma(lib, "libusb.a");
>
>This will tell the linker to link in the library, but you'll still have to 
>define all the function signatures yourself.
>
>And with DLLs, you can use implib to generate a .def file which can be 
>passed on the command line to tell the linker where to find the functions, 
>but again, you have to define all the function signatures.
>
>Some people have been working on "auto-loading" symbols from static / 
>dynamic libraries, but it's not part of the language yet.  I think a D 
>object / library standard that had auto-loading of symbols would be great. 
>
>

I really hope "auto-loading" gets into the standard. It seems like there is alot
of "fluff" when including/importing libraries... there are many steps/programs
to do essentially one thing -- reference external (pre-compiled) code. We have
'implib', 'linkdef', 'pragma', 'extern' (for *every* function you want to
use),'import'... and you still have to add the library filenames to the command
line during compilation (unless you use pragma as Jarrett pointed out...).

Merge all that functionality into one keyword -- for example, you shouldn't have
to tell the compiler anything more than 'I want to use this external source'.
One line would tell the compiler you want to link/import a file, and that all
symbols are to be loaded from that library that are referenced in the program.
You might want to deprecate the current 'import', 'extern' and 'pragma' (pragma
probably has other uses?) for an all-in-one 'reference' keyword that would work
something like:

reference "alleg40.dll"
reference "gameclasses.d"
reference "libusb.a"
reference "phobos.lib"

The library type could be extracted by the file extension. That just looks
awesome :) You have to agree... :) It must be possible -- and I think that would
put D far ahead of the competition... imagine getting a new library -- want to
install it? Copy hotstuff.xxx to the directory and say 'reference
"hotstuff.xxx"' in your Game.d and that's it. Want to compile it? Just say 'dmd
Game.d', that's it (assuming the libraries are in the same directory... -I
otherwise etc etc.) -- If it isn't a recognizable library, throw a compiler
error...

Jeremy



More information about the Digitalmars-d mailing list