Thread overview | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 15, 2006 Trouble with modules | ||||
---|---|---|---|---|
| ||||
I have a file called HttpCommon.d where I am throwing code that needs to be imported by a few files in my project. It contains an enum and a few constants. When I try to to import it, I get the following error: Request.d:5: module HttpCommmon cannot read file 'HttpCommmon.d' HttpCommon.d (in the same directory) contains: //Common globals for HTTP enum Protocol { //Removed } static char[] getProtocolName(Protocol protocol) { //Removed } static Protocol getProtocolByName(char[] name) { //Removed } class StatusCode { //Removed } What's going on? I don't understand how the compiler finds files, but I'm thinking that's where it's going wrong. |
April 15, 2006 Re: Trouble with modules | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Madigan | On Sat, 15 Apr 2006 16:19:36 +1000, Andrew Madigan <amadigan@gmail.com> wrote: > I have a file called HttpCommon.d where I am throwing code that needs to be > imported by a few files in my project. It contains an enum and a few > constants. When I try to to import it, I get the following error: > > Request.d:5: module HttpCommmon cannot read file 'HttpCommmon.d' > > HttpCommon.d (in the same directory) contains: There is a restriction in D in that one cannot have a module with the same name as the directory it appears in. The simple workaround is to rename one or the other. -- Derek Parnell Melbourne, Australia |
April 15, 2006 Re: Trouble with modules | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote:
> On Sat, 15 Apr 2006 16:19:36 +1000, Andrew Madigan <amadigan@gmail.com> wrote:
>
>> I have a file called HttpCommon.d where I am throwing code that needs to
>> be
>> imported by a few files in my project. It contains an enum and a few
>> constants. When I try to to import it, I get the following error:
>>
>> Request.d:5: module HttpCommmon cannot read file 'HttpCommmon.d'
>>
>> HttpCommon.d (in the same directory) contains:
>
> There is a restriction in D in that one cannot have a module with the same name as the directory it appears in. The simple workaround is to rename one or the other.
>
hmmm, maybe I am misunderstanding, but the directory these files are in is called "dhttp" (I'm on linux, so the path is really just ~/dhttp). The file structure looks like this:
dhttp
Request.d
HttpCommon.d
[other d files]
Makefile
Does HttpCommon need to be in a subdirectory? I admit I find all this a little confusing, Java handles things a little differently.
|
April 15, 2006 Re: Trouble with modules | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Madigan | Andrew Madigan wrote: > I have a file called HttpCommon.d where I am throwing code that needs to be > imported by a few files in my project. It contains an enum and a few > constants. When I try to to import it, I get the following error: > > Request.d:5: module HttpCommmon cannot read file 'HttpCommmon.d' You get this message if you haven't passed a file to the compiler. dmd HttpCommon.d > > HttpCommon.d (in the same directory) contains: > > //Common globals for HTTP > > enum Protocol { > //Removed > } > > static char[] getProtocolName(Protocol protocol) { > //Removed > } > > static Protocol getProtocolByName(char[] name) { > //Removed > } > > class StatusCode { > //Removed > } > > What's going on? I don't understand how the compiler finds files, but I'm > thinking that's where it's going wrong. |
April 15, 2006 Re: Trouble with modules | ||||
---|---|---|---|---|
| ||||
Posted in reply to John C | John C wrote:
> Andrew Madigan wrote:
>> I have a file called HttpCommon.d where I am throwing code that needs to be imported by a few files in my project. It contains an enum and a few constants. When I try to to import it, I get the following error:
>>
>> Request.d:5: module HttpCommmon cannot read file 'HttpCommmon.d'
>
> You get this message if you haven't passed a file to the compiler.
>
> dmd HttpCommon.d
>
>>
>> HttpCommon.d (in the same directory) contains:
>>
>> //Common globals for HTTP
>>
>> enum Protocol {
>> //Removed
>> }
>>
>> static char[] getProtocolName(Protocol protocol) {
>> //Removed
>> }
>>
>> static Protocol getProtocolByName(char[] name) {
>> //Removed
>> }
>>
>> class StatusCode {
>> //Removed
>> }
>>
>> What's going on? I don't understand how the compiler finds files, but I'm thinking that's where it's going wrong.
andymadigan@andym:~/dhttp$ gdc -c Request.d HttpCommon.d Request.d:5: module HttpCommmon cannot read file 'HttpCommmon.d'
Note that HttpCommon.d does build fine.
|
April 15, 2006 Re: Trouble with modules | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Madigan | Andrew Madigan wrote:
>
> andymadigan@andym:~/dhttp$ gdc -c Request.d HttpCommon.d
> Request.d:5: module HttpCommmon cannot read file 'HttpCommmon.d'
>
> Note that HttpCommon.d does build fine.
I have actually done almost this exactly same thing... multiple times. You have three 'm's in HttpCommmon in Request.d line 5.
-- Chris Nicholson-Sauls
|
April 15, 2006 Re: Trouble with modules | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Madigan | On Sat, 15 Apr 2006 18:27:44 +1000, Andrew Madigan <amadigan@gmail.com> wrote: > Derek Parnell wrote: > >> On Sat, 15 Apr 2006 16:19:36 +1000, Andrew Madigan <amadigan@gmail.com> >> wrote: >> >>> I have a file called HttpCommon.d where I am throwing code that needs to >>> be >>> imported by a few files in my project. It contains an enum and a few >>> constants. When I try to to import it, I get the following error: >>> >>> Request.d:5: module HttpCommmon cannot read file 'HttpCommmon.d' >>> >>> HttpCommon.d (in the same directory) contains: >> >> There is a restriction in D in that one cannot have a module with the same >> name as the directory it appears in. The simple workaround is to rename >> one or the other. >> > > hmmm, maybe I am misunderstanding, but the directory these files are in is > called "dhttp" (I'm on linux, so the path is really just ~/dhttp). The file > structure looks like this: > > dhttp > Request.d > HttpCommon.d > [other d files] > Makefile > > Does HttpCommon need to be in a subdirectory? I admit I find all this a > little confusing, Java handles things a little differently. Sorry, it was my misunderstanding (I rushed a reply as I was going out to see my football team play - they lost). Have you tried the Build utility? It would avoid spelling mistakes like this. -- Derek Parnell Melbourne, Australia |
April 15, 2006 Re: Trouble with modules | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Nicholson-Sauls | Chris Nicholson-Sauls wrote:
> Andrew Madigan wrote:
>>
>> andymadigan@andym:~/dhttp$ gdc -c Request.d HttpCommon.d Request.d:5: module HttpCommmon cannot read file 'HttpCommmon.d'
>>
>> Note that HttpCommon.d does build fine.
>
> I have actually done almost this exactly same thing... multiple times. You have three 'm's in HttpCommmon in Request.d line 5.
>
> -- Chris Nicholson-Sauls
Wow, I need to stop making dumb posts to this forum, I must have looked at that same line of code 50 times.
|
April 15, 2006 Re: Trouble with modules | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Madigan | Andrew Madigan wrote: > Chris Nicholson-Sauls wrote: > >> Andrew Madigan wrote: >>> >>> andymadigan@andym:~/dhttp$ gdc -c Request.d HttpCommon.d Request.d:5: module HttpCommmon cannot read file 'HttpCommmon.d' >>> >>> Note that HttpCommon.d does build fine. >> >> I have actually done almost this exactly same thing... multiple times. You have three 'm's in HttpCommmon in Request.d line 5. >> >> -- Chris Nicholson-Sauls > > Wow, I need to stop making dumb posts to this forum, I must have looked at that same line of code 50 times. Allright, now I'm getting a related error, there are two functions defined in HttpCommon.d (they're global). I'm getting errors about multiple definition. What should I do? gdc HttpCommon.d -o http Application.o HttpCommon.o http.o InterruptableThread.o Request.o RequestThread.o RootApplication .o StatusCode.o TestApp.o WebServer.o HttpCommon.o: In function `_D10HttpCommon10HttpCommon15getProtocolNameFE10HttpCommon8ProtocolZAa ':HttpCommon.d:(.text+0x0): multiple definition of `_D10HttpCommon10HttpCommon15getProtocolNameFE10HttpCommon8ProtocolZAa' /tmp/cccBIwTr.o:HttpCommon.d:(.text+0x0): first defined here HttpCommon.o: In function `_D10HttpCommon10HttpCommon17getProtocolByNameFAaZE10HttpCommon8Protocol ':HttpCommon.d:(.text+0x5 e): multiple definition of `_D10HttpCommon10HttpCommon17getProtocolByNameFAaZE10HttpCommon8Protocol' /tmp/cccBIwTr.o:HttpCommon.d:(.text+0x5e): first defined here HttpCommon.o:(.rodata+0x14): multiple definition of `_init_10HttpCommon10HttpCommon' /tmp/cccBIwTr.o:(.rodata+0x14): first defined here HttpCommon.o:(.rodata+0x28): multiple definition of `_vtbl_10HttpCommon10HttpCommon' /tmp/cccBIwTr.o:(.rodata+0x28): first defined here HttpCommon.o:(.data+0x0): multiple definition of `_Class_10HttpCommon10HttpCommon' /tmp/cccBIwTr.o:(.data+0x0): first defined here collect2: ld returned 1 exit status make: *** [http] Error 1 |
April 15, 2006 Re: Trouble with modules | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Madigan | Andrew Madigan wrote:
> Allright, now I'm getting a related error, there are two functions defined in HttpCommon.d (they're global). I'm getting errors about multiple definition. What should I do?
>
> gdc HttpCommon.d -o http Application.o HttpCommon.o http.o
> InterruptableThread.o Request.o RequestThread.o RootApplication
> .o StatusCode.o TestApp.o WebServer.o
> HttpCommon.o: In function
> `_D10HttpCommon10HttpCommon15getProtocolNameFE10HttpCommon8ProtocolZAa
> ':HttpCommon.d:(.text+0x0):
> multiple definition of
> `_D10HttpCommon10HttpCommon15getProtocolNameFE10HttpCommon8ProtocolZAa'
> /tmp/cccBIwTr.o:HttpCommon.d:(.text+0x0): first defined here
> HttpCommon.o: In function
> `_D10HttpCommon10HttpCommon17getProtocolByNameFAaZE10HttpCommon8Protocol
> ':HttpCommon.d:(.text+0x5
> e): multiple definition of
> `_D10HttpCommon10HttpCommon17getProtocolByNameFAaZE10HttpCommon8Protocol'
> /tmp/cccBIwTr.o:HttpCommon.d:(.text+0x5e): first defined here
> HttpCommon.o:(.rodata+0x14): multiple definition of
> `_init_10HttpCommon10HttpCommon'
> /tmp/cccBIwTr.o:(.rodata+0x14): first defined here
> HttpCommon.o:(.rodata+0x28): multiple definition of
> `_vtbl_10HttpCommon10HttpCommon'
> /tmp/cccBIwTr.o:(.rodata+0x28): first defined here
> HttpCommon.o:(.data+0x0): multiple definition of
> `_Class_10HttpCommon10HttpCommon'
> /tmp/cccBIwTr.o:(.data+0x0): first defined here
> collect2: ld returned 1 exit status
> make: *** [http] Error 1
>
It seems like you're compiling both HttpCommon.d and HttpCommon.o, and that they're conflicting with each other.
|
Copyright © 1999-2021 by the D Language Foundation