DMD Refuses to Compile Multiple Source Files

Samwise via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jan 17 18:35:39 PST 2017


Alright. For the sake of this argument, I'm going to post all the 
stuff about a really tiny boring program that quite literally 
does nothing, even though I found this issue when I was working 
with a much larger project with more functions. Basically I'm 
getting errors when I attempt to compile multiple source files 
using the DMD. It does not matter whether it's through dub or 
just straight DMD. A few little code snippets and DMD output (The 
dub output is basically the same as the DMD, just with a few more 
lines):

hello.d (This file contains the main function, as you can see. I 
put the headers in here to simplify things.):

import std.stdio;

int getReturnCode();

int main() {
	writeln("Hello World!");
	return getReturnCode();
}

getReturnCode.d (This file is the home of my cute function, which 
does nothing...):

int getReturnCode() {
	return 4;
}

Those were the complete contents of my two basic program files. 
The Compilation works fine (Can generate both object files using 
the -c switch with the DMD). However, it just stops when 
linking...

$ dmd getReturnCode.d hello.d
getReturnCode.o: In function `_Dmain':
hello.d:(.text._Dmain+0x17): undefined reference to 
`_D5hello13getReturnCodeFZi'
collect2: error: ld returned 1 exit status
--- errorlevel 1

This basic output is what I'm getting whenever I try to compile a 
main function using a function call that is for a function not 
included in the main.d, regardless of pretty much any other thing.

Thank you for reading and at least attempting to help me solve 
this issue...
~Sam


More information about the Digitalmars-d-learn mailing list