D:dmd说真的很奇怪 [英] D: dmd saying something really bizarre
问题描述
我正在为自己编写一个库,以帮助自动化一些真正常见的任务,我一直在做D从命令行脚本。作为参考,下面是整个代码:
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;
}
现在,当我尝试在调试模式下编译时(dmd -debug) ,我收到此错误消息:
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
我完全不知道我在这里做错了什么。我使用Windows 7,如果这有帮助。
I have absolutely no idea what I did wrong here. I'm using Windows 7, if that helps at all.
推荐答案
这些错误消息来自OPTLINK,链接器D使用用于编译32位Windows程序。
These error messages are coming from OPTLINK, the linker D uses for compiling 32-bit Windows programs.
如果您试图将库编译为 .lib
文件,您需要使用 -lib
编译器开关在编译后调用库管理器(而不是链接器)。 (技术上DMD的库管理员是编译器内置的,因此它直接发出 .lib
。)
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.)
要将一个模块编译为 .obj
文件,请使用 -c
选项来禁止调用链接器。
If you only intended to compile one module to a .obj
file, use the -c
option to suppress invoking the linker.
如果既没有指定 -lib
也没有指定 -c
编译后调用链接器,这将尝试将源文件构建到可执行程序中。如果你的源文件没有一个入口点( main
函数),链接器将会抱怨无开始地址。
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".
如果你正在尝试构建一个使用你的库的程序,并且你只在调试模式下得到链接错误,它可能表明链接器找不到标准库的调试版本。此设置使用 -debuglib
开关指定,通常它与非调试库相同(也可以使用 defaultlib
switch)。
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).
这篇关于D:dmd说真的很奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!