Setting up dmd properly

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jan 11 20:15:36 PST 2016


On Monday, 11 January 2016 at 16:27:54 UTC, Jason Jeffory wrote:

>>
>> Anyway, regarding the static libs. I used this on a Win64 
>> project and it works:
>>
>>        "lflags" : [
>>          
>> "D:\\develop\\cairo\\cairo\\src\\release\\cairo-static.lib",
>>          "D:\\develop\\cairo\\libpng\\libpng.lib",
>>          "gdi32.lib"
>>        ],
>
> Thanks, that works but

lflags is probably not the best way to do it. The "libs" field is 
better. This will guarantee that the library is passed in a 
compiler-appropriate manner across platforms. lflags is 
compiler-specific.

> 1. *not a valid lib file* (glfw3.lib) ;/ Ok,

It's likely a COFF vs OMF issue.

> 2. What about 64? Does one have to maintain two branches for 
> that?

No. You might keep the libraries in separate directories or use a 
naming convention (like appending -32 or -64 on the library 
names) to distinguish them. Using DUB, you could then add 
something like the following:

"libs-windows-dmd-x86": ["myWinLib-32"],
"libs-windows-dmd-x86_64": ["myWinLib-64"]

Drop the "windows" bit for cross-platform stuff. Of course, this 
is dependent upon you passing -ax86_64 to DUB when you want to 
compile for 64-bit


>
> 1. Trying windows link instead, remember having problems like 
> this in the past with optlink.
>
> "LINK : fatal error LNK1104: cannot open file '_CMDLINE'"
>
> ;/
>
> tried converting with coffimplib, not an import library. 
> Another rabbit hole to go down ;/ (Why do programmers make 
> programmers life hell?)

coffimplib [1] is for converting import libraries, not static 
libraries. You can also use implib (part of the basic utilities 
package [2]) to generate an import library if you have a DLL. You 
should use coff2omf [3] to convert static libraries and object 
files.

You can avoid all of these headaches by using dynamic bindings 
like those at DerelictOrg [4] if they are available for the 
libraries you use. Then the compile-time dependency on the C 
library goes away and all you need is the DLL at runtime.

[1] http://www.digitalmars.com/ctg/coffimplib.html
[2] http://www.digitalmars.com/download/freecompiler.html
[3] http://www.digitalmars.com/ctg/coff2omf.html
[4] https://github.com/DerelictOrg


More information about the Digitalmars-d-learn mailing list