www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Using the -I flag in Linux

reply PaperPilot <jaltman77096 yahoo.com> writes:
Hi all:

I am compiling a D language program in two files and getting an ld error.

The files are: hello.d which has the main() routine.
Word.d has a class which is instantiated in hello

If I compile both files together like:

dmd hello Word

the program compiles and links successfully. If I compile Word.d first and then
hello.d and include the working directory like:

dmd hello -I~/sandbox where sandbox is the working directory I get linker
errors like: undefined reference to '_D4Word12__ModuleInfoZ'

D uses the gcc linker, ld, and I installed gcc 4.1.2 to get it. Is there
another package I need to install?

Thanks in advance.
Dec 27 2007
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
"PaperPilot" wrote
 Hi all:

 I am compiling a D language program in two files and getting an ld error.

 The files are: hello.d which has the main() routine.
 Word.d has a class which is instantiated in hello

 If I compile both files together like:

 dmd hello Word

 the program compiles and links successfully. If I compile Word.d first and 
 then hello.d and include the working directory like:

 dmd hello -I~/sandbox where sandbox is the working directory I get linker 
 errors like: undefined reference to '_D4Word12__ModuleInfoZ'
You need to include the object file that Word produced. It's just like a normal C link. Try: dmd hello Word.o -I~/sandbox Note that D still imports via source files (or D interface files), not via object files. So when you import something you are not importing the object into the build, you are simply having the compiler re-parse the source file. This is why it is generally more efficient (time-wise) to compile all your source files at once, as the compiler only parses each file once. This is distinctly different from Java, which imports the compiled file. -Steve
Dec 27 2007
parent reply PaperPilot <jaltman77096 yahoo.com> writes:
Steven Schveighoffer Wrote:

 
 You need to include the object file that Word produced.  It's just like a 
 normal C link.  Try:
 
 dmd hello Word.o -I~/sandbox
 
 Note that D still imports via source files (or D interface files), not via 
 object files.  So when you import something you are not importing the object 
 into the build, you are simply having the compiler re-parse the source file. 
 This is why it is generally more efficient (time-wise) to compile all your 
 source files at once, as the compiler only parses each file once.
 
 This is distinctly different from Java, which imports the compiled file.
 
 -Steve 
 
 
Does this mean I still have to list all my object files on the command line? That could make quite a long entry. Joel
Dec 27 2007
next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"PaperPilot" <jaltman77096 yahoo.com> wrote in message 
news:fl0osg$1p1r$1 digitalmars.com...

 Does this mean I still have to list all my object files on the command 
 line?  That could make quite a long entry.
Only if you don't compile the files that they come from. i.e. this will work: dmd file1.d file2.d But if you compile them separately: dmd file1.d -c dmd file2.d file1.obj or dmd file1.d file2.d -c dmd file1.obj file2.obj So you only have to list object files of files you don't compile in the same command. This is no different from C or C++.
Dec 27 2007
parent PaperPilot <jaltman77096 yahoo.com> writes:
Jarrett Billingsley Wrote:

 
 Only if you don't compile the files that they come from.
 
 i.e. this will work:
 
 dmd file1.d file2.d
 
 But if you compile them separately:
 
 dmd file1.d -c
 dmd file2.d file1.obj
 
 or
 
 dmd file1.d file2.d -c
 dmd file1.obj file2.obj
 
 So you only have to list object files of files you don't compile in the same 
 command.
 
 This is no different from C or C++. 
 
 
I compiled dmd hello.d Word.d -v Both files were parsed. dmd hello.o Word.d -v Word.d was parsed. dmd hello.d Word.o -v Only hello.d was parsed. Then I did: dmd hello.o Word.o -v All I got was an expanded command line. It looks like the object files are passed to the linker no matter when they were generated.
Dec 27 2007
prev sibling parent reply =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= <jeberger free.fr> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

PaperPilot wrote:
 Steven Schveighoffer Wrote:
 
 You need to include the object file that Word produced.  It's just like a 
 normal C link.  Try:

 dmd hello Word.o -I~/sandbox

 Note that D still imports via source files (or D interface files), not via 
 object files.  So when you import something you are not importing the object 
 into the build, you are simply having the compiler re-parse the source file. 
 This is why it is generally more efficient (time-wise) to compile all your 
 source files at once, as the compiler only parses each file once.

 This is distinctly different from Java, which imports the compiled file.

 -Steve 
Does this mean I still have to list all my object files on the command line? That could make quite a long entry.
That's why we have tools such as dsss or SCons... Jerome - -- +------------------------- Jerome M. BERGER ---------------------+ | mailto:jeberger free.fr | ICQ: 238062172 | | http://jeberger.free.fr/ | Jabber: jeberger jabber.fr | +---------------------------------+------------------------------+ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQFHc/CDd0kWM4JG3k8RAmKpAJ9pTdc6HBA33T9b4mO1A4S2D70pyACgsZ+m wHkywgqTcY2+lp+5xPVp3zk= =jcd4 -----END PGP SIGNATURE-----
Dec 27 2007
next sibling parent PaperPilot <jaltman77096 yahoo.com> writes:
Jérôme M. Berger Wrote:
 
 PaperPilot wrote:
 Does this mean I still have to list all my object files on the command line? 
That could make quite a long entry.
 
That's why we have tools such as dsss or SCons... Jerome
I've checked out dsss and SCons and they look like reasonable tools. I will have to try them. Thanks a lot, Joel
Dec 27 2007
prev sibling parent Derek Parnell <derek psych.ward> writes:
On Thu, 27 Dec 2007 19:35:47 +0100, "Jérôme M. Berger" wrote:

 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 PaperPilot wrote:
 Steven Schveighoffer Wrote:
 
 You need to include the object file that Word produced.  It's just like a 
 normal C link.  Try:

 dmd hello Word.o -I~/sandbox

 Note that D still imports via source files (or D interface files), not via 
 object files.  So when you import something you are not importing the object 
 into the build, you are simply having the compiler re-parse the source file. 
 This is why it is generally more efficient (time-wise) to compile all your 
 source files at once, as the compiler only parses each file once.

 This is distinctly different from Java, which imports the compiled file.

 -Steve 
Does this mean I still have to list all my object files on the command line? That could make quite a long entry.
That's why we have tools such as dsss or SCons...
And 'Bud' ( http://www.dsource.org/projects/build ) Note that the -I switch is used to specify a location for imports. Object files are *not* imported so the -I switch has nothing to do with object files. The full path of each object files is required on the command line, though if that can be expressed as one relative to the current directory you can specify it that way too. The D copmiler does not read object files but merely passes them, as specified, to the linker. -- Derek Parnell Melbourne, Australia skype: derek.j.parnell
Dec 27 2007