On Monday, 24 March 2008 at 17:41:11 UTC, Steven Schveighoffer wrote:
I know you fixed the problem, but just an FYI, the reason is because when you import rollDice, you bring both rollDice the module and rollDice the function into the global namespace (which confuses the compiler 'cause it doesn't know what symbol you want to use). This is normally avoided in libraries by having a package tree. So for example, if you created everything in the subdirectory foo, and had your modules be:

module foo.diceroller;
import foo.rollDice;

Then the import would import the module foo.rollDice, and the function rollDice, and the compiler would no longer be confused about what you are trying to call.

IMO, this makes it difficult to write multi-file applications that live in one directory. It would be nice if this was changed...


I know this thread is quite old but I still seem to be getting a similar error and don't understand how to resolve it. I currently have a program isPrime.d that I would like to reuse in other programs:

bool isPrime(int n) {
    // logic to check if n is prime

import isPrime;
void main() {

Both files are in the same directory. When compiling main.d, I get: Error: function expected before (), not module isPrime of type void

I've tried changing the name of the function isPrime in isPrime.d to something else (as well as changing the name in the main program) but then I get an error similar to:
In function `_Dmain':
main.d:(.text._Dmain[_Dmain]+0x83): undefined reference to `_D7isPrime3isPFiZb'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1

Thanks in advance.

Reply via email to