www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Import module

reply "codenstuff" <nikolapav1985 gmail.com> writes:
I am trying to import module and compile.

The compiler produces message

map/map.d(9): Error: module game_object is in file 
'steering/game_object.d' which cannot be read
import path[0] = /usr/include/dmd/phobos
import path[1] = /usr/include/dmd/druntime/import
make: *** [main] Error 1

How can I compile? Is it possible to modify import path?

Modules are set up as

${HOME}/d_apps/steering (contains steering/game_object.d)
${HOME}/d_apps/path_find (contains map/map.d)

In map.d I import as

import steering.game_object;

The compile command

dmd map/map.d main_visual.d -I${HOME}/d_apps/steering
Jul 09 2015
next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
The best thing to do is to pass all the modules in the project to 
the compiler at once, so like:

dmd map/map.d steering/game_object.d

The import path could be changed to not include the steering/ 
folder - give it the folder that contains steering - but that 
still won't actually link without an extra step (you'd still have 
to compile the other module). Passing it all at once just works.

Alternatively, you might be able to run

rdmd map/map.d

if the folders are predictable enough too.
Jul 09 2015
parent "codenstuff" <nikolapav1985 gmail.com> writes:
On Thursday, 9 July 2015 at 22:10:53 UTC, Adam D. Ruppe wrote:
 The best thing to do is to pass all the modules in the project 
 to the compiler at once, so like:

 dmd map/map.d steering/game_object.d

 The import path could be changed to not include the steering/ 
 folder - give it the folder that contains steering - but that 
 still won't actually link without an extra step (you'd still 
 have to compile the other module). Passing it all at once just 
 works.

 Alternatively, you might be able to run

 rdmd map/map.d

 if the folders are predictable enough too.
This does not work for larger projects (when import is from multiple other projects). Any other way to import modules?
Jul 09 2015
prev sibling parent reply "anonymous" <anonymous example.com> writes:
On Thursday, 9 July 2015 at 22:05:23 UTC, codenstuff wrote:
 I am trying to import module and compile.

 The compiler produces message

 map/map.d(9): Error: module game_object is in file 
 'steering/game_object.d' which cannot be read
 import path[0] = /usr/include/dmd/phobos
 import path[1] = /usr/include/dmd/druntime/import
 make: *** [main] Error 1
This error message doesn't mention the import path you add below with "-I${HOME}/d_apps/steering". It should. Looks like you copied the output of a different command.
 How can I compile? Is it possible to modify import path?

 Modules are set up as

 ${HOME}/d_apps/steering (contains steering/game_object.d)
Is that "${HOME}/d_apps/steering/steering/game_object.d" or is it "${HOME}/d_apps/steering/game_object.d"?
 ${HOME}/d_apps/path_find (contains map/map.d)

 In map.d I import as

 import steering.game_object;

 The compile command

 dmd map/map.d main_visual.d -I${HOME}/d_apps/steering
If the file is "${HOME}/d_apps/steering/steering/game_object.d", then this import path should be ok. If the file is "${HOME}/d_apps/steering/game_object.d", then that import is wrong, and you'd have to pass the import path as "-I${HOME}/d_apps" instead. (Adam D. Ruppe already said the following, but maybe he wasn't verbose enough.) Even when the import path is fixed, this can't compile because you're not passing game_object.d to the compiler. You have multiple options: You can pass all source files to dmd. You don't need to tinker with the import paths then. Or you can use rdmd instead of dmd (or rather on top of it). rdmd takes a single source file, discovers the imported modules, and passes everything to dmd. It needs proper import paths to work its magic, of course.
Jul 09 2015
parent reply "codenstuff" <nikolapav1985 gmail.com> writes:
On Friday, 10 July 2015 at 00:24:44 UTC, anonymous wrote:
 On Thursday, 9 July 2015 at 22:05:23 UTC, codenstuff wrote:
 I am trying to import module and compile.

 The compiler produces message

 map/map.d(9): Error: module game_object is in file 
 'steering/game_object.d' which cannot be read
 import path[0] = /usr/include/dmd/phobos
 import path[1] = /usr/include/dmd/druntime/import
 make: *** [main] Error 1
This error message doesn't mention the import path you add below with "-I${HOME}/d_apps/steering". It should. Looks like you copied the output of a different command.
 How can I compile? Is it possible to modify import path?

 Modules are set up as

 ${HOME}/d_apps/steering (contains steering/game_object.d)
Is that "${HOME}/d_apps/steering/steering/game_object.d" or is it "${HOME}/d_apps/steering/game_object.d"?
 ${HOME}/d_apps/path_find (contains map/map.d)

 In map.d I import as

 import steering.game_object;

 The compile command

 dmd map/map.d main_visual.d -I${HOME}/d_apps/steering
If the file is "${HOME}/d_apps/steering/steering/game_object.d", then this import path should be ok. If the file is "${HOME}/d_apps/steering/game_object.d", then that import is wrong, and you'd have to pass the import path as "-I${HOME}/d_apps" instead. (Adam D. Ruppe already said the following, but maybe he wasn't verbose enough.) Even when the import path is fixed, this can't compile because you're not passing game_object.d to the compiler. You have multiple options: You can pass all source files to dmd. You don't need to tinker with the import paths then. Or you can use rdmd instead of dmd (or rather on top of it). rdmd takes a single source file, discovers the imported modules, and passes everything to dmd. It needs proper import paths to work its magic, of course.
The path is ${HOME}/d_apps/steering/steering/game_object.d Compile command is dmd map/map.d main_visual.d -ofmain_visual -H -gc -unittest -L-lDgame -L-lDerelictUtil -L-lDerelictGL3 -L-lDerelictSDL2 -L-ldl -I/home/real/d_apps/dgame/source -I/home/real/d_apps/derelict_util/source -I/home/real/d_apps/derelict_gl3/source -I/home/real/d_apps/derelict_sdl2/source -I/home/real/d_apps/steering Compiler message is same
Jul 09 2015
next sibling parent reply "Mike Parker" <aldacron gmail.com> writes:
On Friday, 10 July 2015 at 00:53:38 UTC, codenstuff wrote:

 The path is ${HOME}/d_apps/steering/steering/game_object.d

 Compile command is

 dmd map/map.d main_visual.d -ofmain_visual -H -gc -unittest 
 -L-lDgame -L-lDerelictUtil -L-lDerelictGL3 -L-lDerelictSDL2 
 -L-ldl -I/home/real/d_apps/dgame/source 
 -I/home/real/d_apps/derelict_util/source 
 -I/home/real/d_apps/derelict_gl3/source 
 -I/home/real/d_apps/derelict_sdl2/source 
 -I/home/real/d_apps/steering

 Compiler message is same
First, because you are importing sterring.game_object, then you can't pass -I/home/real/d_apps/steering to the compiler -- this will cause it to look for /home/real/d_apps/steering/sterring/game_object.d. You have to pass the parent of the steering directory, i.e. -I/home real/d_apps. Then it will be able to find the import. Second, the above will only solve your immediate problem. The next problem is that you are going to run into linking errors. The -I switch only affects how the compiler can find which symbols are available in a module. It does not affect which modules get compiled. You will still need compile game_object.d, and all of the files from Dgame, DerelictUtil, DerelictGL3 and DerelictSDL2. The latter all have dub configurations that allow you to easily compile them into libraries. Then you can pass all of those on the command line, along with game_object.d (as Adam already recommended). Since all of the projects you are using have dub packages, it will be much easier for you to use dub to manage your own project. Then building becomes this: dub build Much less hassle.
Jul 09 2015
parent "anonymous" <anonymous example.com> writes:
On Friday, 10 July 2015 at 03:11:25 UTC, Mike Parker wrote:
 On Friday, 10 July 2015 at 00:53:38 UTC, codenstuff wrote:

 The path is ${HOME}/d_apps/steering/steering/game_object.d
[...]
 First, because you are importing sterring.game_object, then you 
 can't pass -I/home/real/d_apps/steering to the compiler -- this 
 will cause it to look for 
 /home/real/d_apps/steering/sterring/game_object.d. You have to 
 pass the parent of the steering directory, i.e. -I/home 
 real/d_apps. Then it will be able to find the import.
He said "The path is ${HOME}/d_apps/steering/steering/game_object.d", so "-I/home/real/d_apps/steering" should be correct.
Jul 10 2015
prev sibling parent reply "anonymous" <anonymous example.com> writes:
On Friday, 10 July 2015 at 00:53:38 UTC, codenstuff wrote:
 On Friday, 10 July 2015 at 00:24:44 UTC, anonymous wrote:
 On Thursday, 9 July 2015 at 22:05:23 UTC, codenstuff wrote:
 I am trying to import module and compile.

 The compiler produces message

 map/map.d(9): Error: module game_object is in file 
 'steering/game_object.d' which cannot be read
 import path[0] = /usr/include/dmd/phobos
 import path[1] = /usr/include/dmd/druntime/import
 make: *** [main] Error 1
[...]
 The path is ${HOME}/d_apps/steering/steering/game_object.d

 Compile command is

 dmd map/map.d main_visual.d -ofmain_visual -H -gc -unittest 
 -L-lDgame -L-lDerelictUtil -L-lDerelictGL3 -L-lDerelictSDL2 
 -L-ldl -I/home/real/d_apps/dgame/source 
 -I/home/real/d_apps/derelict_util/source 
 -I/home/real/d_apps/derelict_gl3/source 
 -I/home/real/d_apps/derelict_sdl2/source 
 -I/home/real/d_apps/steering

 Compiler message is same
The error message doesn't list any of your import paths. So I still think that the message doesn't belong to that command. Maybe try reducing things to a smaller, self-contained test case.
Jul 10 2015
parent "codenstuff" <nikolapav1985 gmail.com> writes:
On Friday, 10 July 2015 at 10:22:39 UTC, anonymous wrote:
 On Friday, 10 July 2015 at 00:53:38 UTC, codenstuff wrote:
 On Friday, 10 July 2015 at 00:24:44 UTC, anonymous wrote:
[...]
[...]
 The path is ${HOME}/d_apps/steering/steering/game_object.d

 Compile command is

 dmd map/map.d main_visual.d -ofmain_visual -H -gc -unittest 
 -L-lDgame -L-lDerelictUtil -L-lDerelictGL3 -L-lDerelictSDL2 
 -L-ldl -I/home/real/d_apps/dgame/source 
 -I/home/real/d_apps/derelict_util/source 
 -I/home/real/d_apps/derelict_gl3/source 
 -I/home/real/d_apps/derelict_sdl2/source 
 -I/home/real/d_apps/steering

 Compiler message is same
The error message doesn't list any of your import paths. So I still think that the message doesn't belong to that command. Maybe try reducing things to a smaller, self-contained test case.
ok thanks that worked
Jul 10 2015