FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Can't use modules functions in main function?

 
Post new topic   Reply to topic     Forum Index -> General
View previous topic :: View next topic  
Author Message
Hero Doug



Joined: 17 Aug 2008
Posts: 4

PostPosted: Sun Aug 17, 2008 7:22 am    Post subject: Can't use modules functions in main function? Reply with quote

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
View user's profile Send private message
michaelp



Joined: 27 Jul 2008
Posts: 114

PostPosted: Sun Aug 17, 2008 8:06 am    Post subject: Reply with quote

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
View user's profile Send private message
csauls



Joined: 27 Mar 2004
Posts: 278

PostPosted: Mon Aug 18, 2008 9:21 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> General All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group