View previous topic :: View next topic |
Author |
Message |
Hero Doug
Joined: 17 Aug 2008 Posts: 4
|
Posted: Sun Aug 17, 2008 7:22 am Post subject: Can't use modules functions in main function? |
|
|
This is fairly similar to the example given on the Digital Mars site, yet it does not work, can't figure out why.
WHen I try to call a modules function from the main method I get a compile error, but outside the main method it works fine. Any ideas why?
The module
Code: |
module A;
void foo();
void bar();
|
This is the main function
Code: |
module B;
import A;
void test() {
foo(); // works as expected
}
void main() {
foo(); // compiler error
}
|
This is the compiler error
Quote: |
OPTLINK (R) for Win32 Release 8.00.1
Copyright (C) Digital Mars 1989-2004 All rights reserved.
main.obj(main)
Error 42: Symbol Undefined _D1A3fooFZv
--- errorlevel 1
|
|
|
Back to top |
|
|
michaelp
Joined: 27 Jul 2008 Posts: 114
|
Posted: Sun Aug 17, 2008 8:06 am Post subject: |
|
|
In the file with the main function, try taking out the module B; part. I don't think you give the file that has main in it a name.
What compiler are you using, and what are you trying to compile with?
( dmd b.d a.d ??) |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Mon Aug 18, 2008 9:21 pm Post subject: |
|
|
Every module (which in all current cases means file) has a module name. If you don't provide one, it is derived directly from the filename with no package. ie, given a file "foo.d" with no module statement, it will become module "foo".
Judging from the linker error given, I'd say he simply hadn't provided both modules on the command line. Make sure you are compiling with:
dmd a b
(The ".d" extension is actually optional, as its expected to be that anyhow.)
If just that doesn't fix things... then I really have no idea. Also, for large projects (as I'm sure you don't want to list twenty or fifty modules on a command line) its best to get familiar with a build utility such as Bud or DSSS/rebuild.
Bud -- http://dsource.org/projects/build
DSSS/rebuild -- http://dsource.org/projects/dsss _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
|