Using the -I flag in Linux

Steven Schveighoffer schveiguy at yahoo.com
Thu Dec 27 08:37:12 PST 2007


"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 





More information about the Digitalmars-d mailing list