www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Linkage

reply Karl Bochert <Karl_member pathlink.com> writes:
I'm trying to call a function in one file from another.
In particular I take the the winsamp.d demo ( where WinMain() calls myWinMain()
) and I move the myWinMain() fucntion to a new file (winapp.d) and lable it
'export'. Both files compile, but the linker complains that myWinMain() is not
found. More confusingly, if I leave myWinMain() in the winsamp.d file as well as
putting it in the second file, the linker complains that it CAN find both
myWinMain() functions.

So how do I link a function across files??
Jul 03 2006
next sibling parent reply Lars Ivar Igesund <larsivar igesund.net> writes:
Karl Bochert wrote:

 I'm trying to call a function in one file from another.
 In particular I take the the winsamp.d demo ( where WinMain() calls
 myWinMain() ) and I move the myWinMain() fucntion to a new file (winapp.d)
 and lable it 'export'. Both files compile, but the linker complains that
 myWinMain() is not found. More confusingly, if I leave myWinMain() in the
 winsamp.d file as well as putting it in the second file, the linker
 complains that it CAN find both myWinMain() functions.
 
 So how do I link a function across files??
Note that export don't make much sense in this case. A function in one file can be used in the other if the file is imported: file1.d ------------ module file1; void foo() {} file2.d ----------- module file2; private import file1; main() { foo(); } -- Lars Ivar Igesund blog at http://larsivi.net DSource & #D: larsivi
Jul 03 2006
parent reply Karl Bochert <Karl_member pathlink.com> writes:
In article <e8ar15$14l5$2 digitaldaemon.com>, Lars Ivar Igesund says...
Karl Bochert wrote:

 I'm trying to call a function in one file from another.
 In particular I take the the winsamp.d demo ( where WinMain() calls
 myWinMain() ) and I move the myWinMain() fucntion to a new file (winapp.d)
 and lable it 'export'. Both files compile, but the linker complains that
 myWinMain() is not found. More confusingly, if I leave myWinMain() in the
 winsamp.d file as well as putting it in the second file, the linker
 complains that it CAN find both myWinMain() functions.
 
 So how do I link a function across files??
Note that export don't make much sense in this case. A function in one file can be used in the other if the file is imported: file1.d ------------ module file1; void foo() {} file2.d ----------- module file2; private import file1; main() { foo(); } -- Lars Ivar Igesund blog at http://larsivi.net DSource & #D: larsivi
Which brings up another question: As I understand it, if file1 were in a subdirectory, it would be: import subdir.file1 Suppose file1.d is in a parallel directory -- i.e. '..\utildir\file1.d' ? or in the parent directory '..' ?
Jul 03 2006
parent Lars Ivar Igesund <larsivar igesund.net> writes:
Karl Bochert wrote:

 In article <e8ar15$14l5$2 digitaldaemon.com>, Lars Ivar Igesund says...
Karl Bochert wrote:

 I'm trying to call a function in one file from another.
 In particular I take the the winsamp.d demo ( where WinMain() calls
 myWinMain() ) and I move the myWinMain() fucntion to a new file
 (winapp.d) and lable it 'export'. Both files compile, but the linker
 complains that myWinMain() is not found. More confusingly, if I leave
 myWinMain() in the winsamp.d file as well as putting it in the second
 file, the linker complains that it CAN find both myWinMain() functions.
 
 So how do I link a function across files??
Note that export don't make much sense in this case. A function in one file can be used in the other if the file is imported: file1.d ------------ module file1; void foo() {} file2.d ----------- module file2; private import file1; main() { foo(); } -- Lars Ivar Igesund blog at http://larsivi.net DSource & #D: larsivi
Which brings up another question: As I understand it, if file1 were in a subdirectory, it would be: import subdir.file1 Suppose file1.d is in a parallel directory -- i.e. '..\utildir\file1.d' ? or in the parent directory '..' ?
You will then need to pass the root dir for the import to the compiler, for instance -I.. or -I../utildir -- Lars Ivar Igesund blog at http://larsivi.net DSource & #D: larsivi
Jul 03 2006
prev sibling parent Karl Bochert <Karl_member pathlink.com> writes:
Note that export don't make much sense in this case. A function in one file
can be used in the other if the file is imported:

file1.d
------------
module file1;

void foo() {}

file2.d
-----------
module file2;

private import file1;

main()
{
foo();
}



-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource & #D: larsivi

--------------------------------

Which brings up another question:

As I understand it, if file1.d were in a subdirectory, it would be:
import subdir.file1

Suppose file1.d was in the parent (..\file1.d) or parallel (..\dir\file1.d)?
Jul 03 2006