www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Compiling+Linking problem : some black magic

reply Denis R <denis_r telkomsa.net> writes:
Hello, 

I've run into linking problem, which to me is somehow related perhaps to my not
understanding of how modules interract.

Below are 2 ways of compiling my project, one i would prefer (for my own
makefile), which is not working (but i dont understand why), 
the other (i've checked it from the output of dmake tool) is working:

Method 1 (working): just all on same line :
dmd -v -c -op   dlanchat_nc.d  comms/chatcomm.d  comms/evcomm.d  util/dutil.d 
dncurses/ncwindow.d  dncurses/ncincludes.d 	dncurses/ncerrors.d
Then linking step

Method 2 (not working): in steps
dmd -v -c -op util/dutil.d 
dmd -v -c -op comms/evcomm.d util/dutil.o
dmd -v -c -op comms/chatcomm.d comms/evcomm.o util/dutil.o
dmd -v -c -op dncurses/ncincludes.d
dmd -v -c -op dncurses/ncerrors.d
dmd -v -c -op dncurses/ncwindow.d dncurses/ncincludes.o dncurses/ncerrors.o


Linking after either of compiling steps:
dmd -v -op dlanchat_nc.d comms/chatcomm.o comms/evcomm.o util/dutil.o
dncurses/ncwindow.o dncurses/ncincludes.o dncurses/ncerrors.o -L-lncurses

which gives, if compiling with method 2, this error :

comms/chatcomm.o(.data+0x394): undefined reference to `_ModuleInfo_4util5dutil'
collect2: ld returned 1 exit status
--- errorlevel 1

All module declarations and imports are in order

Does this mean that you always have to put everything on one line, with the
main file ?
If not, which part of the D docs explains this compiling rules. 
I really have to know, its irritating me that its not working :)
Jun 19 2005
parent reply Derek Parnell <derek psych.ward> writes:
On Sun, 19 Jun 2005 13:49:39 +0200, Denis R wrote:

 Hello, 
 
 I've run into linking problem, which to me is somehow related perhaps to my
not understanding of how modules interract.
 
 Below are 2 ways of compiling my project, one i would prefer (for my own
makefile), which is not working (but i dont understand why), 
 the other (i've checked it from the output of dmake tool) is working:
 
 Method 1 (working): just all on same line :
 dmd -v -c -op   dlanchat_nc.d  comms/chatcomm.d  comms/evcomm.d  util/dutil.d 
dncurses/ncwindow.d  dncurses/ncincludes.d 	dncurses/ncerrors.d
 Then linking step
 
 Method 2 (not working): in steps
 dmd -v -c -op util/dutil.d 
 dmd -v -c -op comms/evcomm.d util/dutil.o
 dmd -v -c -op comms/chatcomm.d comms/evcomm.o util/dutil.o
 dmd -v -c -op dncurses/ncincludes.d
 dmd -v -c -op dncurses/ncerrors.d
 dmd -v -c -op dncurses/ncwindow.d dncurses/ncincludes.o dncurses/ncerrors.o
 
 
 Linking after either of compiling steps:
 dmd -v -op dlanchat_nc.d comms/chatcomm.o comms/evcomm.o util/dutil.o
dncurses/ncwindow.o dncurses/ncincludes.o dncurses/ncerrors.o -L-lncurses
 
 which gives, if compiling with method 2, this error :
 
 comms/chatcomm.o(.data+0x394): undefined reference to `_ModuleInfo_4util5dutil'
 collect2: ld returned 1 exit status
 --- errorlevel 1
 
 All module declarations and imports are in order
 
 Does this mean that you always have to put everything on one line, with the
main file ?
 If not, which part of the D docs explains this compiling rules. 
 I really have to know, its irritating me that its not working :)
The compiler never reads a .o file, so if you are not linking you never need to have those on the command line. The compiler only compiles the .d files. The unix linker is a bit simple-minded, in that it only reads the object and library files in the order they are presented on the command line. If "chatcomm" is referencing anything in "dutil.o" then you might need to reorder the files on the command line. I'm not sure about that but its worth a try. Have you tried my Build utility. It's like dmake but more sophistcated and handles a lot more situations. Normally one would only need to type in ... build util/dutil.d assuming you have either pragma(lib, "ncurses"); or version(build) pragma(link, "ncurses"); somewhere in your sources. You can download it from www.dsource.com/projects/build Even if you want to maintain your own makefile, you can look at the output of Build (the .rsp file) to see which files are required in the makefile. -- Derek Parnell Melbourne, Australia BUILD v2.08 is now available. 29/May/2005 19/06/2005 10:23:16 PM
Jun 19 2005
next sibling parent Denis R <denis_r telkomsa.net> writes:
On Sun, 19 Jun 2005 22:33:11 +1000
Derek Parnell <derek psych.ward> wrote:

Err, but my linking step is the same, that is, same order of files to the
linker, as you can see, independent of my compiling steps.

So its like there is some unseen step dmd -c -op does when i give all files on
same line :)

 On Sun, 19 Jun 2005 13:49:39 +0200, Denis R wrote:
 
 Hello, 
 
 I've run into linking problem, which to me is somehow related perhaps to my
not understanding of how modules interract.
 
 Below are 2 ways of compiling my project, one i would prefer (for my own
makefile), which is not working (but i dont understand why), 
 the other (i've checked it from the output of dmake tool) is working:
 
 Method 1 (working): just all on same line :
 dmd -v -c -op   dlanchat_nc.d  comms/chatcomm.d  comms/evcomm.d  util/dutil.d 
dncurses/ncwindow.d  dncurses/ncincludes.d 	dncurses/ncerrors.d
 Then linking step
 
 Method 2 (not working): in steps
 dmd -v -c -op util/dutil.d 
 dmd -v -c -op comms/evcomm.d util/dutil.o
 dmd -v -c -op comms/chatcomm.d comms/evcomm.o util/dutil.o
 dmd -v -c -op dncurses/ncincludes.d
 dmd -v -c -op dncurses/ncerrors.d
 dmd -v -c -op dncurses/ncwindow.d dncurses/ncincludes.o dncurses/ncerrors.o
 
 
 Linking after either of compiling steps:
 dmd -v -op dlanchat_nc.d comms/chatcomm.o comms/evcomm.o util/dutil.o
dncurses/ncwindow.o dncurses/ncincludes.o dncurses/ncerrors.o -L-lncurses
 
 which gives, if compiling with method 2, this error :
 
 comms/chatcomm.o(.data+0x394): undefined reference to `_ModuleInfo_4util5dutil'
 collect2: ld returned 1 exit status
 --- errorlevel 1
 
 All module declarations and imports are in order
 
 Does this mean that you always have to put everything on one line, with the
main file ?
 If not, which part of the D docs explains this compiling rules. 
 I really have to know, its irritating me that its not working :)
The compiler never reads a .o file, so if you are not linking you never need to have those on the command line. The compiler only compiles the .d files. The unix linker is a bit simple-minded, in that it only reads the object and library files in the order they are presented on the command line. If "chatcomm" is referencing anything in "dutil.o" then you might need to reorder the files on the command line. I'm not sure about that but its worth a try. Have you tried my Build utility. It's like dmake but more sophistcated and handles a lot more situations. Normally one would only need to type in ... build util/dutil.d assuming you have either pragma(lib, "ncurses"); or version(build) pragma(link, "ncurses"); somewhere in your sources. You can download it from www.dsource.com/projects/build Even if you want to maintain your own makefile, you can look at the output of Build (the .rsp file) to see which files are required in the makefile. -- Derek Parnell Melbourne, Australia BUILD v2.08 is now available. 29/May/2005 19/06/2005 10:23:16 PM
Jun 19 2005
prev sibling parent Denis R <denis_r telkomsa.net> writes:
I've seen build before, by the way. But only briefly. There is lots of options
there.

I have to get it now again, and see what it does.

By the way, putting *.o files do dmd -c  is what i've seen dmake does, so i
thought perhaps dmd does something with *.o files, 
if that module is used in the module you are compiling.

Anyway, thanks



On Sun, 19 Jun 2005 22:33:11 +1000
Derek Parnell <derek psych.ward> wrote:

 On Sun, 19 Jun 2005 13:49:39 +0200, Denis R wrote:
 
 Hello, 
 
 I've run into linking problem, which to me is somehow related perhaps to my
not understanding of how modules interract.
 
 Below are 2 ways of compiling my project, one i would prefer (for my own
makefile), which is not working (but i dont understand why), 
 the other (i've checked it from the output of dmake tool) is working:
 
 Method 1 (working): just all on same line :
 dmd -v -c -op   dlanchat_nc.d  comms/chatcomm.d  comms/evcomm.d  util/dutil.d 
dncurses/ncwindow.d  dncurses/ncincludes.d 	dncurses/ncerrors.d
 Then linking step
 
 Method 2 (not working): in steps
 dmd -v -c -op util/dutil.d 
 dmd -v -c -op comms/evcomm.d util/dutil.o
 dmd -v -c -op comms/chatcomm.d comms/evcomm.o util/dutil.o
 dmd -v -c -op dncurses/ncincludes.d
 dmd -v -c -op dncurses/ncerrors.d
 dmd -v -c -op dncurses/ncwindow.d dncurses/ncincludes.o dncurses/ncerrors.o
 
 
 Linking after either of compiling steps:
 dmd -v -op dlanchat_nc.d comms/chatcomm.o comms/evcomm.o util/dutil.o
dncurses/ncwindow.o dncurses/ncincludes.o dncurses/ncerrors.o -L-lncurses
 
 which gives, if compiling with method 2, this error :
 
 comms/chatcomm.o(.data+0x394): undefined reference to `_ModuleInfo_4util5dutil'
 collect2: ld returned 1 exit status
 --- errorlevel 1
 
 All module declarations and imports are in order
 
 Does this mean that you always have to put everything on one line, with the
main file ?
 If not, which part of the D docs explains this compiling rules. 
 I really have to know, its irritating me that its not working :)
The compiler never reads a .o file, so if you are not linking you never need to have those on the command line. The compiler only compiles the .d files. The unix linker is a bit simple-minded, in that it only reads the object and library files in the order they are presented on the command line. If "chatcomm" is referencing anything in "dutil.o" then you might need to reorder the files on the command line. I'm not sure about that but its worth a try. Have you tried my Build utility. It's like dmake but more sophistcated and handles a lot more situations. Normally one would only need to type in ... build util/dutil.d assuming you have either pragma(lib, "ncurses"); or version(build) pragma(link, "ncurses"); somewhere in your sources. You can download it from www.dsource.com/projects/build Even if you want to maintain your own makefile, you can look at the output of Build (the .rsp file) to see which files are required in the makefile. -- Derek Parnell Melbourne, Australia BUILD v2.08 is now available. 29/May/2005 19/06/2005 10:23:16 PM
Jun 19 2005