"Error: function expected before (), not module *module* of type void

Samir samir at aol.com
Sat Sep 22 02:51:25 UTC 2018


On Saturday, 22 September 2018 at 01:58:57 UTC, Adam D. Ruppe 
wrote:
> You probably shouldn't name a module the same as a member 
> anyway, and it should also have two names, like "module 
> myproject.isprime;"
>
> But the fix here is to just use the full name.
>
> import isPrime;
> void main() {
>   isPrime.isPrime(x); // module_name.member_name
> }
>
> or change the import:
>
> import isPrime : isPrime; // specify you want the same-named 
> member
>
>> Both files are in the same directory. When compiling main.d,
>
> When compiling, be sure to pass both modules to it, or use the 
> dmd -i if on a new version.
>
> dmd -i main.d
>
> or
>
> dmd main.d isPrime.d
>
>> main.d:(.text._Dmain[_Dmain]+0x83): undefined reference to 
>> `_D7isPrime3isPFiZb'
>
> this likely means you forgot to compile in the isPrime module, 
> so use the above dmd lines

Thanks for your help, Adam!  Right after posting my question, I 
started reading this site:
https://www.tutorialspoint.com/d_programming/d_programming_modules.htm

Based on that and your recommendation, here is what I ended up 
doing:
I changed the filename of isPrime.d to isprime.d and put that in 
the subdirectory func/:

func/isprime.d:
module func.isprime;
bool isPrime(int n) {
     // check to see if n is prime
}

I then changed main.d to:
import func.isprime;
void main() {
     isPrime(x);
}

Finally, per your suggestion, I compiled it using:
     dmd -i main.d

Thanks again!


More information about the Digitalmars-d-learn mailing list