Jump to page: 1 2
Thread overview
Newbie questions: I love them...! Do you?
Mar 10, 2005
jicman
Mar 10, 2005
clayasaurus
Mar 10, 2005
clayasaurus
Mar 10, 2005
jicman
Mar 12, 2005
jicman
Mar 12, 2005
jicman
Mar 12, 2005
Derek Parnell
Mar 12, 2005
Derek Parnell
Mar 12, 2005
jicman
Mar 12, 2005
Derek Parnell
Mar 12, 2005
jicman
March 10, 2005
Here's one then...:-)

how do I import my own code into a program?  Say I have a bunch of subroutine that I use for myself to ease my programming life (I'm sure we all have them)... How do I incorporate them into my programs?  Sorry, but I just figured I should start to do this.  I used to have one file per program, which was ok, but I am finding myself into having to change many files after fixing a bug. :-)  I know: "ROOKIE!"

Ok, so how do I do it?  Also, how do I fix them?  For example, what if some of those functions use std.string.WhatEver, do I have to import std.string in that function part?

Please help a poor d programmer wanna be...

thanks,

josé


March 10, 2005
jicman wrote:
> Here's one then...:-)
> 
> how do I import my own code into a program?  Say I have a bunch of subroutine
> that I use for myself to ease my programming life (I'm sure we all have them)...
> How do I incorporate them into my programs?  Sorry, but I just figured I should
> start to do this.  I used to have one file per program, which was ok, but I am
> finding myself into having to change many files after fixing a bug. :-)  I know:
> "ROOKIE!"

------------ file1.d -----------------------
module subroutine; // module declaration here

import std.string; // import here

dance()
{
   rock();
}

rock()
{
   std.string.WhatEver(); // or just call WhatEver();
}

------------- main.d -----------------------
import subroutine; // module name

int main()
{
   dance(); // or you could use file1.dance()
   return 0;
}


> 
> Ok, so how do I do it?  Also, how do I fix them?  For example, what if some of
> those functions use std.string.WhatEver, do I have to import std.string in that
> function part?

no.

> 
> Please help a poor d programmer wanna be...
> 

k.

> thanks,
> 

np.

> josé
> 
> 


March 10, 2005
clayasaurus wrote:
> jicman wrote:
> 
>> Here's one then...:-)
>>
>> how do I import my own code into a program?  Say I have a bunch of subroutine
>> that I use for myself to ease my programming life (I'm sure we all have them)...
>> How do I incorporate them into my programs?  Sorry, but I just figured I should
>> start to do this.  I used to have one file per program, which was ok, but I am
>> finding myself into having to change many files after fixing a bug. :-)  I know:
>> "ROOKIE!"
> 
> 
> ------------ file1.d -----------------------
should be
------------- subroutine.d -------------------


> module subroutine; // module declaration here
> 
> import std.string; // import here
> 
> dance()
> {
>    rock();
> }
> 
> rock()
> {
>    std.string.WhatEver(); // or just call WhatEver();
> }
> 
> ------------- main.d -----------------------
> import subroutine; // module name
> 
> int main()
> {
>    dance(); // or you could use file1.dance()

// or you could use subroutine.dance();

just messed up the fnames.

>    return 0;
> }
> 
> 
>>
>> Ok, so how do I do it?  Also, how do I fix them?  For example, what if some of
>> those functions use std.string.WhatEver, do I have to import std.string in that
>> function part?
> 
> 
> no.
> 
>>
>> Please help a poor d programmer wanna be...
>>
> 
> k.
> 
>> thanks,
>>
> 
> np.
> 
>> josé
>>
>>
> 
> 
March 10, 2005

thanks,


clayasaurus says...
>
>clayasaurus wrote:
>> jicman wrote:
>> 
>>> Here's one then...:-)
>>>
>>> how do I import my own code into a program?  Say I have a bunch of
>>> subroutine
>>> that I use for myself to ease my programming life (I'm sure we all
>>> have them)...
>>> How do I incorporate them into my programs?  Sorry, but I just figured
>>> I should
>>> start to do this.  I used to have one file per program, which was ok,
>>> but I am
>>> finding myself into having to change many files after fixing a bug.
>>> :-)  I know:
>>> "ROOKIE!"
>> 
>> 
>> ------------ file1.d -----------------------
>should be
>------------- subroutine.d -------------------
>
>
>> module subroutine; // module declaration here
>> 
>> import std.string; // import here
>> 
>> dance()
>> {
>>    rock();
>> }
>> 
>> rock()
>> {
>>    std.string.WhatEver(); // or just call WhatEver();
>> }
>> 
>> ------------- main.d -----------------------
>> import subroutine; // module name
>> 
>> int main()
>> {
>>    dance(); // or you could use file1.dance()
>
>// or you could use subroutine.dance();
>
>just messed up the fnames.
>
>>    return 0;
>> }
>> 
>> 
>>>
>>> Ok, so how do I do it?  Also, how do I fix them?  For example, what if
>>> some of
>>> those functions use std.string.WhatEver, do I have to import
>>> std.string in that
>>> function part?
>> 
>> 
>> no.
>> 
>>>
>>> Please help a poor d programmer wanna be...
>>>
>> 
>> k.
>> 
>>> thanks,
>>>
>> 
>> np.
>> 
>>> josé
>>>
>>>
>> 
>> 


March 12, 2005
clayasaurus says...
>>------------- subroutine.d -------------------
>> module subroutine; // module declaration here
>> 
>> import std.string; // import here
>> 
>> dance()
>> {
>>    rock();
>> }
>> 
>> rock()
>> {
>>    std.string.WhatEver(); // or just call WhatEver();
>> }
>> 
>> ------------- main.d -----------------------
>> import subroutine; // module name
>> 
>> int main()
>> {
>>    dance(); // or you could use subroutine.dance();
>>    return 0;
>> }

So I have this in my directory:

03/11/2005  08:35 PM               236 jic.d
03/11/2005  08:35 PM               145 month.d

File jic.d contains:

module jic;
private import std.string;
char[] CallMe(char[] mon)
{
char[] mm = "CallMe " ~ mon;
return(mm);
}

char[] CallMeToo(char[] mon)
{
char[] mm = "CallMeToo " ~ mon;
return(mm);
}

while file month.d contains:

import std.stdio;
import jic;
void main (char[][] args)
{
char[] d;
writefln(jic.CallMe("Jan"));
writefln(jic.CallMeToo("Feb"));
}

when I compile month.d, I get:

20:49:38.41>dmd month.d
c:\dmd\bin\..\..\dm\bin\link.exe month,,,user32+kernel32/noi;
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

month.obj(month)
Error 42: Symbol Undefined _D3jic6CallMeFAaZAa
month.obj(month)
Error 42: Symbol Undefined _D3jic9CallMeTooFAaZAa
--- errorlevel 2

Huh?


March 12, 2005
It's linking them.  Unless I'm mistaken, you'll either need:

dmd month.d jic.d

Or:

dmd -c jic.d
dmd month.d jic.obj

Or similar.  The point is that dmd is automatically calling the linker, which needs to be made aware of all the dependencies.

-[Unknown]


> clayasaurus says...
> 
>>>------------- subroutine.d -------------------
>>>module subroutine; // module declaration here
>>>
>>>import std.string; // import here
>>>
>>>dance()
>>>{
>>>   rock();
>>>}
>>>
>>>rock()
>>>{
>>>   std.string.WhatEver(); // or just call WhatEver();
>>>}
>>>
>>>------------- main.d -----------------------
>>>import subroutine; // module name
>>>
>>>int main()
>>>{
>>>   dance(); // or you could use subroutine.dance();
>>>   return 0;
>>>}
> 
> 
> So I have this in my directory:
> 
> 03/11/2005  08:35 PM               236 jic.d
> 03/11/2005  08:35 PM               145 month.d
> 
> File jic.d contains:
> 
> module jic;
> private import std.string;
> char[] CallMe(char[] mon)
> {
> char[] mm = "CallMe " ~ mon;
> return(mm);
> }
> 
> char[] CallMeToo(char[] mon)
> {
> char[] mm = "CallMeToo " ~ mon;
> return(mm);
> }
> 
> while file month.d contains:
> 
> import std.stdio;
> import jic;
> void main (char[][] args)
> {
> char[] d;
> writefln(jic.CallMe("Jan"));
> writefln(jic.CallMeToo("Feb"));
> }
> 
> when I compile month.d, I get:
> 
> 20:49:38.41>dmd month.d
> c:\dmd\bin\..\..\dm\bin\link.exe month,,,user32+kernel32/noi;
> OPTLINK (R) for Win32  Release 7.50B1
> Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved
> 
> month.obj(month)
> Error 42: Symbol Undefined _D3jic6CallMeFAaZAa
> month.obj(month)
> Error 42: Symbol Undefined _D3jic9CallMeTooFAaZAa
> --- errorlevel 2
> 
> Huh?
> 
> 
March 12, 2005
On Sat, 12 Mar 2005 01:46:51 +0000 (UTC), jicman wrote:

> clayasaurus says...
>>>------------- subroutine.d -------------------
>>> module subroutine; // module declaration here
>>> 
>>> import std.string; // import here
>>> 
>>> dance()
>>> {
>>>    rock();
>>> }
>>> 
>>> rock()
>>> {
>>>    std.string.WhatEver(); // or just call WhatEver();
>>> }
>>> 
>>> ------------- main.d -----------------------
>>> import subroutine; // module name
>>> 
>>> int main()
>>> {
>>>    dance(); // or you could use subroutine.dance();
>>>    return 0;
>>> }
> 
> So I have this in my directory:
> 
> 03/11/2005  08:35 PM               236 jic.d
> 03/11/2005  08:35 PM               145 month.d
> 
> File jic.d contains:
> 
> module jic;
> private import std.string;
> char[] CallMe(char[] mon)
> {
> char[] mm = "CallMe " ~ mon;
> return(mm);
> }
> 
> char[] CallMeToo(char[] mon)
> {
> char[] mm = "CallMeToo " ~ mon;
> return(mm);
> }
> 
> while file month.d contains:
> 
> import std.stdio;
> import jic;
> void main (char[][] args)
> {
> char[] d;
> writefln(jic.CallMe("Jan"));
> writefln(jic.CallMeToo("Feb"));
> }
> 
> when I compile month.d, I get:
> 
> 20:49:38.41>dmd month.d
> c:\dmd\bin\..\..\dm\bin\link.exe month,,,user32+kernel32/noi;
> OPTLINK (R) for Win32  Release 7.50B1
> Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved
> 
> month.obj(month)
> Error 42: Symbol Undefined _D3jic6CallMeFAaZAa
> month.obj(month)
> Error 42: Symbol Undefined _D3jic9CallMeTooFAaZAa
> --- errorlevel 2
> 
> Huh?

Either run

  dmd month.d jic.d

or

  build month


The reason is that "dmd month.d" will compile 'month.d' and then link 'month.obj'. You also need to compile 'jic'd' and link that in too.

My 'build' utility will organize these dependencies for you.
-- 
Derek Parnell
Melbourne, Australia
http://www.dsource.org/projects/build
12/03/2005 4:31:30 PM
March 12, 2005
On Sat, 12 Mar 2005 16:33:09 +1100, Derek Parnell wrote:

> On Sat, 12 Mar 2005 01:46:51 +0000 (UTC), jicman wrote:
> 
>> clayasaurus says...
>>>>------------- subroutine.d -------------------
>>>> module subroutine; // module declaration here
>>>> 
>>>> import std.string; // import here
>>>> 
>>>> dance()
>>>> {
>>>>    rock();
>>>> }
>>>> 
>>>> rock()
>>>> {
>>>>    std.string.WhatEver(); // or just call WhatEver();
>>>> }
>>>> 
>>>> ------------- main.d -----------------------
>>>> import subroutine; // module name
>>>> 
>>>> int main()
>>>> {
>>>>    dance(); // or you could use subroutine.dance();
>>>>    return 0;
>>>> }
>> 
>> So I have this in my directory:
>> 
>> 03/11/2005  08:35 PM               236 jic.d
>> 03/11/2005  08:35 PM               145 month.d
>> 
>> File jic.d contains:
>> 
>> module jic;
>> private import std.string;
>> char[] CallMe(char[] mon)
>> {
>> char[] mm = "CallMe " ~ mon;
>> return(mm);
>> }
>> 
>> char[] CallMeToo(char[] mon)
>> {
>> char[] mm = "CallMeToo " ~ mon;
>> return(mm);
>> }
>> 
>> while file month.d contains:
>> 
>> import std.stdio;
>> import jic;
>> void main (char[][] args)
>> {
>> char[] d;
>> writefln(jic.CallMe("Jan"));
>> writefln(jic.CallMeToo("Feb"));
>> }
>> 
>> when I compile month.d, I get:
>> 
>> 20:49:38.41>dmd month.d
>> c:\dmd\bin\..\..\dm\bin\link.exe month,,,user32+kernel32/noi;
>> OPTLINK (R) for Win32  Release 7.50B1
>> Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved
>> 
>> month.obj(month)
>> Error 42: Symbol Undefined _D3jic6CallMeFAaZAa
>> month.obj(month)
>> Error 42: Symbol Undefined _D3jic9CallMeTooFAaZAa
>> --- errorlevel 2
>> 
>> Huh?
> 
> Either run
> 
>   dmd month.d jic.d
> 
> or
> 
>   build month
> 
> 
> The reason is that "dmd month.d" will compile 'month.d' and then link 'month.obj'. You also need to compile 'jic'd' and link that in too.
> 
> My 'build' utility will organize these dependencies for you.

Ok, now that DMD has a lib pragma, you can also do this ...

First create a library that contains jic.obj
   dmd -c jic
   lib -c jic jic,obj

then add "pragma(lib "jic.lib") to month.d and run

  dmd month.d


To create the month.exe

-- 
Derek Parnell
Melbourne, Australia
12/03/2005 4:56:30 PM
March 12, 2005
Thank you.  That was it.

josé

Unknown W. Brackets says...
>
>It's linking them.  Unless I'm mistaken, you'll either need:
>
>dmd month.d jic.d
>
>Or:
>
>dmd -c jic.d
>dmd month.d jic.obj
>
>Or similar.  The point is that dmd is automatically calling the linker, which needs to be made aware of all the dependencies.
>
>-[Unknown]
>
>
>> clayasaurus says...
>> 
>>>>------------- subroutine.d -------------------
>>>>module subroutine; // module declaration here
>>>>
>>>>import std.string; // import here
>>>>
>>>>dance()
>>>>{
>>>>   rock();
>>>>}
>>>>
>>>>rock()
>>>>{
>>>>   std.string.WhatEver(); // or just call WhatEver();
>>>>}
>>>>
>>>>------------- main.d -----------------------
>>>>import subroutine; // module name
>>>>
>>>>int main()
>>>>{
>>>>   dance(); // or you could use subroutine.dance();
>>>>   return 0;
>>>>}
>> 
>> 
>> So I have this in my directory:
>> 
>> 03/11/2005  08:35 PM               236 jic.d
>> 03/11/2005  08:35 PM               145 month.d
>> 
>> File jic.d contains:
>> 
>> module jic;
>> private import std.string;
>> char[] CallMe(char[] mon)
>> {
>> char[] mm = "CallMe " ~ mon;
>> return(mm);
>> }
>> 
>> char[] CallMeToo(char[] mon)
>> {
>> char[] mm = "CallMeToo " ~ mon;
>> return(mm);
>> }
>> 
>> while file month.d contains:
>> 
>> import std.stdio;
>> import jic;
>> void main (char[][] args)
>> {
>> char[] d;
>> writefln(jic.CallMe("Jan"));
>> writefln(jic.CallMeToo("Feb"));
>> }
>> 
>> when I compile month.d, I get:
>> 
>> 20:49:38.41>dmd month.d
>> c:\dmd\bin\..\..\dm\bin\link.exe month,,,user32+kernel32/noi;
>> OPTLINK (R) for Win32  Release 7.50B1
>> Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved
>> 
>> month.obj(month)
>> Error 42: Symbol Undefined _D3jic6CallMeFAaZAa
>> month.obj(month)
>> Error 42: Symbol Undefined _D3jic9CallMeTooFAaZAa
>> --- errorlevel 2
>> 
>> Huh?
>> 
>> 


March 12, 2005
Derek Parnell says...
>
>On Sat, 12 Mar 2005 01:46:51 +0000 (UTC), jicman wrote:
>
>> clayasaurus says...
>>>>------------- subroutine.d -------------------
>>>> module subroutine; // module declaration here
>>>> 
>>>> import std.string; // import here
>>>> 
>>>> dance()
>>>> {
>>>>    rock();
>>>> }
>>>> 
>>>> rock()
>>>> {
>>>>    std.string.WhatEver(); // or just call WhatEver();
>>>> }
>>>> 
>>>> ------------- main.d -----------------------
>>>> import subroutine; // module name
>>>> 
>>>> int main()
>>>> {
>>>>    dance(); // or you could use subroutine.dance();
>>>>    return 0;
>>>> }
>> 
>> So I have this in my directory:
>> 
>> 03/11/2005  08:35 PM               236 jic.d
>> 03/11/2005  08:35 PM               145 month.d
>> 
>> File jic.d contains:
>> 
>> module jic;
>> private import std.string;
>> char[] CallMe(char[] mon)
>> {
>> char[] mm = "CallMe " ~ mon;
>> return(mm);
>> }
>> 
>> char[] CallMeToo(char[] mon)
>> {
>> char[] mm = "CallMeToo " ~ mon;
>> return(mm);
>> }
>> 
>> while file month.d contains:
>> 
>> import std.stdio;
>> import jic;
>> void main (char[][] args)
>> {
>> char[] d;
>> writefln(jic.CallMe("Jan"));
>> writefln(jic.CallMeToo("Feb"));
>> }
>> 
>> when I compile month.d, I get:
>> 
>> 20:49:38.41>dmd month.d
>> c:\dmd\bin\..\..\dm\bin\link.exe month,,,user32+kernel32/noi;
>> OPTLINK (R) for Win32  Release 7.50B1
>> Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved
>> 
>> month.obj(month)
>> Error 42: Symbol Undefined _D3jic6CallMeFAaZAa
>> month.obj(month)
>> Error 42: Symbol Undefined _D3jic9CallMeTooFAaZAa
>> --- errorlevel 2
>> 
>> Huh?
>
>Either run
>
>  dmd month.d jic.d

Derek, this works... but this


>  build month

with your 1.12 build for windows does not.  I get,

8:00:20.96>build month
c:\dmd\bin\..\..\dm\bin\link.exe month,month.exe,,user32+kernel32/noi;
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

month.obj(month)
Error 42: Symbol Undefined _D3jic6CallMeFAaZAa
month.obj(month)
Error 42: Symbol Undefined _D3jic9CallMeTooFAaZAa
--- errorlevel 2

>The reason is that "dmd month.d" will compile 'month.d' and then link 'month.obj'. You also need to compile 'jic'd' and link that in too.
>
>My 'build' utility will organize these dependencies for you.

Well, it's not doing it.  Also, I think I found a bug on it.  But, explain to me why it's not working and I'll tell you the bug. ;-)

josé


« First   ‹ Prev
1 2