I am new to the D language. I am attempting to import my custom class for use in the main() function.
Project struture:
DlangApp/app.d
DlangApp/ClassOne.d
ClassOne.d:
import std.stdio;
class ClassOne
{
string firstName;
string lastName;
this(string first, string last)
{
firstName = first;
lastName = last;
}
void writeName()
{
writefln("The name is: %s %s", firstName, lastName);
}
}
app.d:
import std.stdio;
import ClassOne;
void main()
{
auto aNumber = 10;
auto aString = "This is a string.";
writefln("A string: %s\nA number: %s", aString, aNumber);
}
When I run dmd -run app.d
, I get this error message:
app.obj(app)
Error 42: Symbol Undefined _D8ClassOne12__ModuleInfoZ
---errorlevel 1
What am I doing wrong here?
Execute dmd -ofquakkels_app app.d ClassOne.d
and, if the compilation was successfull, you will get the quakkels_app
executable.
Or, if you really want to use the -run <file> [args...]
parameter: dmd ClassOne.d -run app.d
. Note that I put -run at the end - because after -run filename you may want to put some parameters that you want to pass to your application.
Now you probably understand why you got the compilation error above - simply DMD did not compile ClassOne.d file...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With