digitalmars.D.learn - How to use the -I command line switch?
- tipdbmp (19/19) Jan 03 2018 // C:\libs\my_module.d
- jmh530 (3/22) Jan 03 2018 dmd main.d C:\libs\my_module.d
- tipdbmp (4/5) Jan 03 2018 That does not use the -I switch.
- jmh530 (6/11) Jan 03 2018 I tried a few other options, but I don't use it enough to know
- =?UTF-8?Q?Ali_=c3=87ehreli?= (9/17) Jan 03 2018 -I is for import directives only. imports are needed to compile the
- Tony (7/23) Jan 03 2018 What about the error message? If -I is only for DMD finding
- =?UTF-8?Q?Ali_=c3=87ehreli?= (9/17) Jan 03 2018 Yeah, there's definitely a problem there.
- jmh530 (3/11) Jan 03 2018 Is there any way to re-write the documentation so its clearer?
- Tony (17/36) Jan 03 2018 As has already been mentioned, the -I is not used for
// C:\libs\my_module.d module my_module; void foo() {} // main.d module main; import my_module; void main() { foo(); } Running dmd with: dmd -IC:\libs main.d my_module.d I get: Error: module my_module is in file 'my_module.d' which cannot be read import path[0] = C:\libs import path[1] = path\to\dmd\D\dmd2\windows\bin\..\..\src\phobos import path[2] = path\to\dmd\D\dmd2\windows\bin\..\..\src\druntime\import
Jan 03 2018
On Wednesday, 3 January 2018 at 12:21:28 UTC, tipdbmp wrote:// C:\libs\my_module.d module my_module; void foo() {} // main.d module main; import my_module; void main() { foo(); } Running dmd with: dmd -IC:\libs main.d my_module.d I get: Error: module my_module is in file 'my_module.d' which cannot be read import path[0] = C:\libs import path[1] = path\to\dmd\D\dmd2\windows\bin\..\..\src\phobos import path[2] = path\to\dmd\D\dmd2\windows\bin\..\..\src\druntime\importdmd main.d C:\libs\my_module.d I usually use dub for this type of thing...
Jan 03 2018
dmd main.d C:\libs\my_module.dThat does not use the -I switch. It compiles if I specify the full path to my_module.d: dmd -IC:\libs main.d C:\libs\my_module.d I don't understand the error message though.
Jan 03 2018
On Wednesday, 3 January 2018 at 17:10:22 UTC, tipdbmp wrote:I tried a few other options, but I don't use it enough to know the trick to get it working. I tend to use either dub, setting the path environmental variables, or the absolute path. Hopefully someone else can let you know. If it's a bug, it should be in bugzilla, but sometimes I just assume I screwed something up.dmd main.d C:\libs\my_module.dThat does not use the -I switch. It compiles if I specify the full path to my_module.d: dmd -IC:\libs main.d C:\libs\my_module.d I don't understand the error message though.
Jan 03 2018
On 01/03/2018 09:10 AM, tipdbmp wrote:-I is for import directives only. imports are needed to compile the importing module. All other modules still need to be compiled themselves and added to the program either as individual .o files or as libraries (e.g. .a, .lib, etc.). The method you've shown is a shorthand for "compile each to .o and add each to the program." Working as expected... :) Alidmd main.d C:\libs\my_module.dThat does not use the -I switch. It compiles if I specify the full path to my_module.d: dmd -IC:\libs main.d C:\libs\my_module.d I don't understand the error message though.
Jan 03 2018
On Wednesday, 3 January 2018 at 18:35:21 UTC, Ali Çehreli wrote:On 01/03/2018 09:10 AM, tipdbmp wrote:What about the error message? If -I is only for DMD finding "import ..." files, and not files on the command line, why does DMD list what was in the -I "where to look for import directives" when saying that it can't find a command-line file? It says that it can't locate my_module.d and then lists the directory that my_module.d is in.-I is for import directives only. imports are needed to compile the importing module. All other modules still need to be compiled themselves and added to the program either as individual .o files or as libraries (e.g. .a, .lib, etc.). The method you've shown is a shorthand for "compile each to .o and add each to the program." Working as expected... :)dmd main.d C:\libs\my_module.dThat does not use the -I switch. It compiles if I specify the full path to my_module.d: dmd -IC:\libs main.d C:\libs\my_module.d I don't understand the error message though.
Jan 03 2018
On 01/03/2018 01:42 PM, Tony wrote:On Wednesday, 3 January 2018 at 18:35:21 UTC, Ali Çehreli wrote:Yeah, there's definitely a problem there. It's possible that the compiler is acting like this: Because there is already my_module.d on the command line, it assumes that main's 'import my_module' must mean that file. Because there is no such file in the local directory, it errors out by using a generic error message function, which does not explain the situation well. I made that all up but I bet it's something like that. :) AliWorking as expected... :)What about the error message? If -I is only for DMD finding "import ..." files, and not files on the command line, why does DMD list what was in the -I "where to look for import directives" when saying that it can't find a command-line file? It says that it can't locate my_module.d and then lists the directory that my_module.d is in.
Jan 03 2018
On Wednesday, 3 January 2018 at 18:35:21 UTC, Ali Çehreli wrote:-I is for import directives only. imports are needed to compile the importing module. All other modules still need to be compiled themselves and added to the program either as individual .o files or as libraries (e.g. .a, .lib, etc.). The method you've shown is a shorthand for "compile each to .o and add each to the program." Working as expected... :) AliIs there any way to re-write the documentation so its clearer? I've been confused by this before as well...
Jan 03 2018
On Wednesday, 3 January 2018 at 21:51:07 UTC, jmh530 wrote:On Wednesday, 3 January 2018 at 18:35:21 UTC, Ali Çehreli wrote:Which documentation are you referring to? If it's the specification, just click "edit".-I is for import directives only. imports are needed to compile the importing module. All other modules still need to be compiled themselves and added to the program either as individual .o files or as libraries (e.g. .a, .lib, etc.). The method you've shown is a shorthand for "compile each to .o and add each to the program." Working as expected... :) AliIs there any way to re-write the documentation so its clearer? I've been confused by this before as well...
Jan 03 2018
On Wednesday, 3 January 2018 at 22:52:10 UTC, Seb wrote:Which documentation are you referring to? If it's the specification, just click "edit".I know how to edit it. I just don't know how to word it so that it isn't so confusing.
Jan 03 2018
On Wednesday, 3 January 2018 at 12:21:28 UTC, tipdbmp wrote:// C:\libs\my_module.d module my_module; void foo() {} // main.d module main; import my_module; void main() { foo(); } Running dmd with: dmd -IC:\libs main.d my_module.d I get: Error: module my_module is in file 'my_module.d' which cannot be read import path[0] = C:\libs import path[1] = path\to\dmd\D\dmd2\windows\bin\..\..\src\phobos import path[2] = path\to\dmd\D\dmd2\windows\bin\..\..\src\druntime\importAs has already been mentioned, the -I is not used for command-line files. Just compiling (-c option) shows that the -I is enough for DMD to find the import file: dmd -c main.d -Ic:\libs successfully compiles main.d into main.obj To do a full compile and link of main without compiling my_module.d each time: C:\libs>dmd -lib -ofmy_module.lib my_module.d creates "my_module.lib". Then use it to link with in main.d compile/link: C:\code\d\forum>dmd main.d -Ic:\libs -Llib c:\libs\my_module OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html OPTLINK : Warning 9: Unknown Option : NOILIB main.exe is created even though there is a mysterious warning.
Jan 03 2018