torhu wrote:
On 11.11.2009 04:57, Sean Fennell wrote:
I'm very green to D, just learning it now.
I have a module that I wrote. Its pretty simple, just helper
functions to get input from user as certain data types
GetInt()
GetString()
GetChar()
etc...
I compiled the module using dmd -lib mymod.d which output mymod.a
Now I've imported my module into ask.d to test it and I get the
folliowing linking error when I try to compile:
ask.o:(.data+0x4c): undefined reference to `_D4mymod12__ModuleInfoZ`
My dir structure looks like this:
project/
---ask.d
---lib/
------mymod.d
------mymod.a
and my import line is:
import lib.mymod;
Anyone seen this before? Using linux dmd v2.036
Thanks!
You have to hand all the files to the compiler, otherwise there will be
missing symbols when the compiler runs the linker.
Like this:
dmd ask lib/mymod
Compiling to a library first, like you did, will work too. But you have
to hand the compiler everything when you want to create the actual
executable:
dmd ask lib/mymod.a
There are build tools, like dsss, that will automate this for you.
I've found rdmd to be a very useful program. It will track down all
imports in your program and feed the relevant files to the compiler.
Here are some examples:
To compile and run your program:
rdmd ask
To compile, but not run your program:
rdmd --build-only ask
Actually, I tend to just put a shebang line in my main D source file and
mark it as executable:
ask.d:
#!/path/to/rdmd --shebang
import lib.mymod;
...
Then, after you make changes to your program and want to test it, you
just run ./ask.d. :)
Note that rdmd only creates a temporary executable, so it's more of a
testing tool than a build tool.
-Lars