www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - [linux, ubuntu] personal D module not found in the same directory

reply "le TeXnicien de surface" <le.texnicien.de.surface chezmoi.invalid> writes:
hello all

I'm begining to learn to program with D.

I've made this tiny module written in file truc.d
<module>
module truc;

double carre(double x){
     return x*x;
}
</module>

and this tiny program written in file jeteste.d

<prgm>
import truc;  // I've also tried import T = truc;
import std.stdio;

double cube(double x){
     return x*x*x;
}

void main(){
     double y = 5;
     auto z = carre(y);
     // alt version :
     // auto z = T.carre(y);
     writeln("vu ici ",z);
}
</prgm>

Both files are in the same directory.

I run dmd jeteste.d in the said directory

and I obtain this message:

jeteste.o: In function `_Dmain':
jeteste.d:(.text._Dmain+0x1e): undefined reference to
`_D4truc5carreFdZd'
collect2: ld a retourné 1 code d'état d'exécution
--- errorlevel 1

where do I err?

any hint would be greatly appreciated

many thanks in advance
Jun 26 2012
next sibling parent "Jesse Phillips" <Jessekphillips+D gmail.com> writes:
On Tuesday, 26 June 2012 at 16:55:56 UTC, le TeXnicien de surface 
wrote:

 and I obtain this message:

 jeteste.o: In function `_Dmain':
 jeteste.d:(.text._Dmain+0x1e): undefined reference to
 `_D4truc5carreFdZd'
 collect2: ld a retourné 1 code d'état d'exécution
 --- errorlevel 1

 where do I err?

 any hint would be greatly appreciated

 many thanks in advance

D uses a Compile -> link model (like most). You have hit a linker error, it can not link to an object you haven't given. But on that the compiler only compiled one file. dmd allFiles.d Of.d theProject.d This will compile the files and pass them to the linker. You can learn about linking to find out how to handle libraries.
Jun 26 2012
prev sibling next sibling parent "le TeXnicien de surface" <le.texnicien.de.surface chezmoi.invalid> writes:
On Tuesday, 26 June 2012 at 17:14:07 UTC, Jesse Phillips wrote:
 On Tuesday, 26 June 2012 at 16:55:56 UTC, le TeXnicien de 
 surface wrote:

 and I obtain this message:

 jeteste.o: In function `_Dmain':
 jeteste.d:(.text._Dmain+0x1e): undefined reference to
 `_D4truc5carreFdZd'
 collect2: ld a retourné 1 code d'état d'exécution
 --- errorlevel 1

 where do I err?

 any hint would be greatly appreciated

 many thanks in advance

D uses a Compile -> link model (like most). You have hit a linker error, it can not link to an object you haven't given. But on that the compiler only compiled one file. dmd allFiles.d Of.d theProject.d This will compile the files and pass them to the linker. You can learn about linking to find out how to handle libraries.

Thank you very much. I really was at my wit's end :(
Jun 26 2012
prev sibling next sibling parent "Graham Fawcett" <fawcett uwindsor.ca> writes:
On Tuesday, 26 June 2012 at 17:23:58 UTC, le TeXnicien de surface 
wrote:
 On Tuesday, 26 June 2012 at 17:14:07 UTC, Jesse Phillips wrote:
 On Tuesday, 26 June 2012 at 16:55:56 UTC, le TeXnicien de 
 surface wrote:

 and I obtain this message:

 jeteste.o: In function `_Dmain':
 jeteste.d:(.text._Dmain+0x1e): undefined reference to
 `_D4truc5carreFdZd'
 collect2: ld a retourné 1 code d'état d'exécution
 --- errorlevel 1

 where do I err?

 any hint would be greatly appreciated

 many thanks in advance

D uses a Compile -> link model (like most). You have hit a linker error, it can not link to an object you haven't given. But on that the compiler only compiled one file. dmd allFiles.d Of.d theProject.d This will compile the files and pass them to the linker. You can learn about linking to find out how to handle libraries.


You should also be able to do this: rdmd --build-only jeteste.d Normally, the rdmd tool will compile and immediately execute the "jeteste" program. Rdmd is "smarter" than dmd, because it will calculate all the files that you need to compile and link. However, rdmd stores the executable in a different ("hidden") directory. (On my computer, it is storing the executable in "/tmp/.rdmd-1000/.../".) But you can call rdmd as "rdmd --build-only". This will compile the executable in the *current* directory, and will not execute it. Best, Graham
Jun 26 2012
prev sibling parent "le TeXnicien de surface" <le.texnicien.de.surface chezmoi.invalid> writes:
On Tuesday, 26 June 2012 at 19:50:15 UTC, Graham Fawcett wrote:
 You should also be able to do this:

   rdmd --build-only jeteste.d

 Normally, the rdmd tool will compile and immediately execute 
 the "jeteste" program. Rdmd is "smarter" than dmd, because it 
 will calculate all the files that you need to compile and link. 
 However, rdmd stores the executable in a different ("hidden") 
 directory. (On my computer, it is storing the executable in 
 "/tmp/.rdmd-1000/.../".)

 But you can call rdmd as "rdmd --build-only". This will compile 
 the executable in the *current* directory, and will not execute 
 it.

Thanks a lot. This is very interresting. I do learn here!
Jun 26 2012