digitalmars.D - link pragma?
- novice2 (27/27) Dec 18 2004 Hi.
- Garett Bass (8/36) Dec 18 2004 I asked for something along these lines a couple of months
- John Reimer (28/65) Dec 18 2004 These are excellent ideas. Several people have already thought of these...
- John Reimer (13/19) Dec 18 2004 Note that Derek Parnell's modifications to dmake, yet unreleased,
- Derek (12/24) Dec 18 2004 Thanks John. Yes I've taken Helmut's code and reworked it considerably. ...
Hi. Sorry, i read D doc and can't find any syntax element to explicitly define library for external function. For example i have windows my.dll, and C function MyCPlusPlusFunc() in it. I make my.lib for my.dll. But i must every compile time point dmd to my.lib. Can i only once in sources explicitly define that library my.lib must be linked for external function? For example, in Delphi we can write somethig like this: {$IFDEF WIN32} function CryptFile external 'advapi32.dll' name '_CryptFileA'; {$ELSE} function CryptFile external 'capi.so' name '_cryptfile'; {$ENDIF} I tried use pragma + modification of dmake utility. The goal is pass to dmake information about library. With this modification Dmake should search lines in sources like this pragma(link,"my.lib"); But dmd don't accept unknown pragma. All i want is D sources distribution and using convenience. Now for import module to my app i must keep in mind wich library i need. If i don't know wich librari i should link, D compiler can't help me diagnose the problem. DMD just will say like "symbol extFunc not resolved". IMHO programmer should have ability to declare required library, so DMD help diagnose the problem. Is it possible? I hope you understand my long english text :)
Dec 18 2004
I asked for something along these lines a couple of months ago. I think it is a great idea and I would really like to see it included. I had a slightly different syntax in mind, because I really think the compiler should be required to handle this: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.Quite a few people responded positively to this suggestion, but I imagine Walter won't even consider it until v.1.0 is complete and bug-free.
Dec 18 2004
novice2 wrote:Hi. Sorry, i read D doc and can't find any syntax element to explicitly define library for external function. For example i have windows my.dll, and C function MyCPlusPlusFunc() in it. I make my.lib for my.dll. But i must every compile time point dmd to my.lib. Can i only once in sources explicitly define that library my.lib must be linked for external function? For example, in Delphi we can write somethig like this: {$IFDEF WIN32} function CryptFile external 'advapi32.dll' name '_CryptFileA'; {$ELSE} function CryptFile external 'capi.so' name '_cryptfile'; {$ENDIF} I tried use pragma + modification of dmake utility. The goal is pass to dmake information about library. With this modification Dmake should search lines in sources like this pragma(link,"my.lib");These are excellent ideas. Several people have already thought of these ideas for 3rd party tools such as dmake. Eventually, I believe, such features will be part of the available build tools' functionality.But dmd don't accept unknown pragma.No, D will not accept them. But such features could be worked into a current build tool like d make. Something like the following could work: version(toolname) { pragma(link,"my.lib") } This way the build tool can search for this version statement and call d appropriately with the correct link arguments. Using version is great because the d compiler itself won't touch or use this version statement for any purpose (unless the code explicitly sets this). I'm interested in seeing a modification of this sort being made available. Other nifty additions, of course, can be added to build tools in a similar fashion. As is, the above example should cause no errors, even in it's unimplemented state, because the version is not defined. Thus, it's a safe solution for future improvement.All i want is D sources distribution and using convenience. Now for import module to my app i must keep in mind wich library i need. If i don't know wich librari i should link, D compiler can't help me diagnose the problem. DMD just will say like "symbol extFunc not resolved". IMHO programmer should have ability to declare required library, so DMD help diagnose the problem. Is it possible?Absoulutely! And there is no need to wait for dmd version 1.0. Tools like dmake could include these features in the future easily enough if everyone agrees upon the solution (and, of course, if Helmut can be convinced :-) ). He says on his wiki site that he's open to suggestions for new dmake features.I hope you understand my long english text :)Your English was perfectly understandable. Thanks for some excellent suggestions. Later, John
Dec 18 2004
novice2 wrote:I tried use pragma + modification of dmake utility. The goal is pass to dmake information about library. With this modification Dmake should search lines in sources like this pragma(link,"my.lib");Note that Derek Parnell's modifications to dmake, yet unreleased, appears to include this functionality already. See the D wiki site for the incomplete details of his project additions to Helmut's dmake: http://www.prowiki.org/wiki4d/wiki.cgi?Dmake/PreparingVs022 This tool has tremendous potential if it takes off. I've already looked into adding some more features to the current project for win32 and linux. The more simplified the compile process becomes for D programmers (especially newcomers), the more desirable the language will become (I think). dmake has the potential to both simplify the build process and add powerfull tools to the build processs. Later, John
Dec 18 2004
On Sat, 18 Dec 2004 12:34:43 -0800, John Reimer wrote:novice2 wrote:Thanks John. Yes I've taken Helmut's code and reworked it considerably. It is almost unrecognizable now ;-) And yes, it does have the ability you describe built into it now. In your D code you would write ... version (build) pragma(link, libname); to cause libname.lib to appear on the optlink command line. It also has the ability to create a library. Next week I'm planning to finalize the tool and release it. By then you will be able to maintain existing libraries as well as create them. -- Derek Melbourne, AustraliaI tried use pragma + modification of dmake utility. The goal is pass to dmake information about library. With this modification Dmake should search lines in sources like this pragma(link,"my.lib");Note that Derek Parnell's modifications to dmake, yet unreleased, appears to include this functionality already. See the D wiki site for the incomplete details of his project additions to Helmut's dmake:
Dec 18 2004