Linking to libraries with D
Bill Baxter
dnewsgroup at billbaxter.com
Fri Nov 16 12:05:01 PST 2007
Jarrod wrote:
> == Quote from Anders Bergh
>> If you use DSSS, you could add this to your curl.d:
>> version(build) pragma(link, "curl");
>> This will work on both Windows and Linux. I'm not actually 100% sure
>> this is the proper "DSSS way", but it works for me.
>> Anders
>
> Anders,
> I think I worded the topic a bit wrong. My issue is not that I can't link with the
> C library, it's more that I can't link with the C library without having to
> compile curl.d.
> I guess it just seems redundant to me that I have to compile what should only
> really be a header file. And I'll be compiling it into a static library no less,
> meaning I needed to make a library just to interface with another library.
Ever heard of "precompiled headers" in C++ land. Do they give you the
shivers just hearing the word? They do me. Because precompiled headers
are an awful collection of vendor specific kludges to try to fix the
terrible performance that comes from the C++ way of textually including
every header file. Because #include just pastes the text in, it means
for every .c/.cpp file the compiler comes across it re-parses and
re-compiles *all* the headers that that .c file depends on in any way.
Doing it the D way with modules means that every file only needs to be
parsed and compiled once. That's part of the reason why D complies so
darn fast compared to C++. It's like "precompiled headers" are always on.
> Not exactly seamless.
> Oh well, just a few more minutes of effort anyway.
Yes, well many folks have complained that bud or dsss-like functionality
should be part of the compiler. That is, dmd should have a way to
recursively compile all imports included from the modules listed on the
compile line. For some reason Walter just doesn't go for it though. I
don't really know why. A lot about D's module system seems to be
inspired by how Java's modules work. But javac does do recursive
imports as far as I recall. I remember it being one of Sun's marketing
points originally: "With java you don't need makefiles! 'javac
main.java' is all you need!" Of course, after people got past writing
little dancing duke applets they realized that a build tool *was* still
needed, so now they have Ant, make redone in XML for some godawful reason.
So maybe I answered my own question. Ant may be why Walter decided not
to bother putting build-tool functionality into dmd. Perhaps he felt
people would inevitably be unsatisfied with whatever limited build tool
functionality is built into the compiler. So best just to keep the
compiler lean and let external tools take care of it from the beginning.
Walter did add one feature to dmd to help writers of such tool, though.
"dmd -v main.d" will list all the imports required by main in an
easy-to-parse format.
--bb
More information about the Digitalmars-d
mailing list