D: dmd saying something really bizarre

喜欢而已 提交于 2019-12-08 02:27:17

问题


I was writing a library for myself to help automate some really common tasks I've been doing in D for scripting from the command line. For reference, here is the code in its entirety:

module libs.script; 

import std.stdio: readln; 
import std.array: split;
import std.string: chomp;
import std.file: File;

//Library code for boring input processing and process invocation for command-line scripting.

export:
//Takes the args given to the program and an expected number of arguments.
//If args is lacking, it will try to grab the arguments it needs from stdin.
//Returns the arguments packed into an array, or null if malformed or missing.
string[] readInput(in string[] args, in size_t expected) {
string[] packed = args.dup;
if (args.length != expected) {
    auto line = split(chomp(readln()), " ");
    if (line.length == (expected - args.length)) 
        packed ~= line; 
    else
        packed = null;
}
return packed;
}

//Digs through the .conf file given by path_to_config for a match for name_to_match in the first column.
//Returns the rest of the row in the .conf file if a match is found, and null otherwise.
string[] readConfig (in string path_to_config, in string name_to_match) {
string[] packed = null;
auto config = File(path_to_config,"r");
while (!config.eof()) {
    auto line = split(chomp(config.readln()), ":");
    if (line[0] == name_to_match)
        packed = line[1..$];
    if (packed !is null)
        break;
}
config.close(); //safety measure
return packed;
}

Now, when I try to compile this in debug mode (dmd -debug), I get this error message:

Error 42: Symbol Undefined __adDupT
script.obj(script)
Error 42: Symbol Undefined __d_arrayappendT
script.obj(script)
Error 42: Symbol Undefined _D3std5stdio4File6__dtorMFZv
script.obj(script)
Error 42: Symbol Undefined _D3std5stdio4File3eofMxFNaNdZb
script.obj(script)
Error 42: Symbol Undefined __d_framehandler
script.obj(script)
Error 42: Symbol Undefined _D3std5stdio4File5closeMFZv
script.obj(script)
Error 42: Symbol Undefined _D3std6string12__ModuleInfoZ
script.obj(script)
Error 42: Symbol Undefined _D3std5stdio12__ModuleInfoZ
OPTLINK : Warning 134: No Start Address
--- errorlevel 36

I have absolutely no idea what I did wrong here. I'm using Windows 7, if that helps at all.


回答1:


These error messages are coming from OPTLINK, the linker D uses for compiling 32-bit Windows programs.

If you're trying to compile your library to a .lib file, you need to use the -lib compiler switch to invoke the librarian (instead of linker) after compilation. (Technically DMD's librarian is built into the compiler, so it emits .lib directly.)

If you only intended to compile one module to a .obj file, use the -c option to suppress invoking the linker.

If neither -lib or -c are specified, DMD will invoke the linker after compilation, which will attempt to build your source files into an executable program. If your none of your source files contain an entry point (main function), the linker will complain about "No Start Address".

If you're trying to build a program that uses your library and you're getting link errors in only debug mode, it probably indicates that the linker can't find the debug version of the standard library. This setting is specified using the -debuglib switch, and usually it is the same as the non-debug library (which can also be specified using the -defaultlib switch).



来源:https://stackoverflow.com/questions/21573495/d-dmd-saying-something-really-bizarre

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!