digitalmars.D.learn - Can't link libs?
- K.K. (55/55) Jun 06 2014 So being a noob and all I've gotten stuck on something stupid...
- Adam D. Ruppe (9/9) Jun 06 2014 When you compile the final program, the library .d file needs to
- K.K. (5/14) Jun 06 2014 Hey Adam!
- Adam D. Ruppe (8/11) Jun 06 2014 If you pass all the .d files at once, you don't need the .lib at
- K.K. (5/17) Jun 06 2014 Oh okay, I get what you mean. I guess I was really over
- Adam D. Ruppe (8/11) Jun 07 2014 Yea, I think a lot of people do: building C++ takes some extra
- K.K. (10/18) Jun 07 2014 I still don't think I've fully figured out compiling in C++! For
- FreeSlave (7/16) Jun 08 2014 You are not ought to have .d files to link with library, because
So being a noob and all I've gotten stuck on something stupid... Whenever I try to compile using DMD, and try to link .lib files I always get errors like: "file4.d(2): Error: module file3 is in file 'file3lib\file3.d' which cannot be read import path[0] = %cd%\file3 import path[1] = C:\dmd2\Windows\bin\..\..\src\phobos import path[2] = C:\dmd2\Windows\bin\..\..\src\druntime\import " For reference on this I've been using Adam's book and this page: http://wiki.dlang.org/Compiling_and_linking_with_DMD_on_Windows I also tried using COFF2OMF and COFFIMPLIB (everytime I used coffimplib it just said "Error: Missing archive signature") Here's the code I was working with (plz excuse my lazy variable/file names, wasn't feeling creative this morning :P): File3.d which I turned into a .lib --------------------------------- module file3lib.file3;;; import std.stdio; class shit { int lead; this(int y){lead += y;} int fuck(int x) { lead += x; return lead; } } /* void main() { auto okay = new shit(10); writeln(okay.fuck(2)); } */ ---------------------------------- file4.d ---------------------------------- module file4; import file3lib.file3; import std.stdio; void main() { auto thing = new shit(2); writeln(thing.fuck(2)); } ---------------------------------- I tried using different names, and making extra directories but that didn't help much ofcourse.. +I know there's that weird thing I did with file3lib & file3, but I swapped that around a bunch of times with no success. Everything's just been getting messier as I go on. I've sortof just been going in circles so if anyone could point out what I'm doing wrong it'd be a huge help! :)
Jun 06 2014
When you compile the final program, the library .d file needs to be available too, either in the folder based on its name or passed straight to dmd explicitly. Despite the presence of the .lib file, the .d file is still needed so it can get code prototypes and type names, etc., out of it. (If you have the .d though, the lib is rarely needed. Indeed, the way I do most D libraries is to just pass all the .d files to the compiler at once and forget about lib files.)
Jun 06 2014
On Friday, 6 June 2014 at 16:33:27 UTC, Adam D. Ruppe wrote:When you compile the final program, the library .d file needs to be available too, either in the folder based on its name or passed straight to dmd explicitly. Despite the presence of the .lib file, the .d file is still needed so it can get code prototypes and type names, etc., out of it. (If you have the .d though, the lib is rarely needed. Indeed, the way I do most D libraries is to just pass all the .d files to the compiler at once and forget about lib files.)Hey Adam! I have kept all the files in one folder. So if I don't need to explicitly call the .lib in DMD, does that mean the .lib is just a passive object? Should I make libs in place of object files?
Jun 06 2014
On Friday, 6 June 2014 at 16:41:24 UTC, K.K. wrote:I have kept all the files in one folder. So if I don't need to explicitly call the .lib in DMD, does that mean the .lib is just a passive object? Should I make libs in place of object files?If you pass all the .d files at once, you don't need the .lib at all and the compiler will also just do one object file. Simplest (and usually fastest!) way to build: dmd yourfile.d otherfile.d lib/file.d lib/otherfile.d otherlib/file.d and so on - then don't worry about object or lib files. Of course if you need a dll or something that's different...
Jun 06 2014
On Friday, 6 June 2014 at 16:52:24 UTC, Adam D. Ruppe wrote:On Friday, 6 June 2014 at 16:41:24 UTC, K.K. wrote:Oh okay, I get what you mean. I guess I was really over complicating it then? xD Thanks for the help Adam! -I'm totally digging your book btw! (I'll save the trouble of figuring out dll's for another day!)I have kept all the files in one folder. So if I don't need to explicitly call the .lib in DMD, does that mean the .lib is just a passive object? Should I make libs in place of object files?If you pass all the .d files at once, you don't need the .lib at all and the compiler will also just do one object file. Simplest (and usually fastest!) way to build: dmd yourfile.d otherfile.d lib/file.d lib/otherfile.d otherlib/file.d and so on - then don't worry about object or lib files. Of course if you need a dll or something that's different...
Jun 06 2014
On Friday, 6 June 2014 at 17:02:33 UTC, K.K. wrote:Oh okay, I get what you mean. I guess I was really over complicating it then? xDYea, I think a lot of people do: building C++ takes some extra steps out of necessity that you can just ignore in D for the most part :)Thanks for the help Adam! -I'm totally digging your book btw!Cool, write amazon reviews when you're done too if you feel like it :P BTW also feel free to ask here or to even email me if you see anything in the book that you want clarification or more info on.
Jun 07 2014
On Saturday, 7 June 2014 at 16:06:39 UTC, Adam D. Ruppe wrote:Yea, I think a lot of people do: building C++ takes some extra steps out of necessity that you can just ignore in D for the most part :)I still don't think I've fully figured out compiling in C++! For compiling the way you showed me, it almost reminds of running and/or compiling python. :3Cool, write amazon reviews when you're done too if you feel like it :PI'm nowhere near done with the book, but I happily wrote you an Amazon review already :) (I think it said they have to review my review first or something? Idk, despite all the shopping on amazon that I do, I rarely write reviews)BTW also feel free to ask here or to even email me if you see anything in the book that you want clarification or more info on.Thanks I'll keep it in mind!
Jun 07 2014
On Friday, 6 June 2014 at 16:33:27 UTC, Adam D. Ruppe wrote:When you compile the final program, the library .d file needs to be available too, either in the folder based on its name or passed straight to dmd explicitly. Despite the presence of the .lib file, the .d file is still needed so it can get code prototypes and type names, etc., out of it. (If you have the .d though, the lib is rarely needed. Indeed, the way I do most D libraries is to just pass all the .d files to the compiler at once and forget about lib files.)You are not ought to have .d files to link with library, because to link you need only interfaces, not implementation (except for templates, since they are not included in object files), otherwise there would be impossible to create closed-source developer libraries. You can generate .di files with dmd -c -o- -H option and use them.
Jun 08 2014