0

全部,

我正在使用 Xamarin Studio 4.08 和 Mono-D 使用 DMD2 编译器对 D 进行编程。当我尝试编译以下内容时(来自The D Programming Language - Alexandrescu , 2010- Page 10):

import std.array;
bool binarySearch(T)(T[] input, T value)
{
    while (!input.empty)
    {
        auto i = input.length / 2;
        auto mid = input[i];
        if(mid > value) input = input[0 .. i];
        else if(mid < value) input = input[i + 1 .. $];
        else return true;
    }
    return false;
}

unittest
{
    assert(binarySearch([1, 3, 6, 7, 9, 15], 6));
    assert(!binarySearch([1, 3, 6, 7, 9, 15], 5));
}

编译时出现以下错误:

: Error: std.array could not be resolved - library reference missing?

但是,当我注释掉时情节变厚了assert(binarySearch([1,3,6,7,9,15], 6));,因为这会产生一个非常特殊的错误:

lolwtfbbq酱

首先,缺少一个库,然后,它是一个 16 位应用程序。我知道这本书有勘误表,但里面没有。

更新

使用相同的代码编译rdmd test.d --main并得到以下错误...

OPTLINK (R) for Win32  Release 8.00.13
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html

OPTLINK : Warning 23: No Stack
C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)

Error 42: Symbol Undefined __fltused
C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
Error 42: Symbol Undefined __d_assert_msg

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
Error 42: Symbol Undefined __d_throwc

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
Error 42: Symbol Undefined _D3std4conv21ConvOverflowException6__ctorMFAyaAyakZC
3std4conv21ConvOverflowException

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
Error 42: Symbol Undefined _D3std4conv21ConvOverflowException7__ClassZ

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
Error 42: Symbol Undefined __d_newclass

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
Error 42: Symbol Undefined _D3std4conv8__assertFiZv

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
Error 42: Symbol Undefined _D3std4conv13ConvException7__ClassZ

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
Error 42: Symbol Undefined _D3std4conv13ConvException6__ctorMFAyaAyakZC3std4con
v13ConvException

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
Error 42: Symbol Undefined _D12TypeInfo_Aya6__initZ

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
Error 42: Symbol Undefined __d_arrayappendT

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D3std6format7__arrayZ

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined __d_arraycopy

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D3std5array7__arrayZ

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _memcpy

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined __d_newitemT

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D4core6memory2GC6extendFNaNbPvkkZk

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D4core6memory2GC6qallocFNaNbkkZS4core6memory8BlkInf
 o_

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined __LDIV@

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D16TypeInfo_Pointer6__vtblZ

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D15TypeInfo_Struct6__vtblZ

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined __ULDIV@

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D3std6format15FormatException6__ctorMFAyaAyakC6obje
 ct9ThrowableZC3std6format15FormatException

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D3std6format15FormatException7__ClassZ

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D3std3utf6encodeFNaNfKG4awZk

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D3std5array8__assertFiZv

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined __d_arraysetcapacity

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D3std3utf8__assertFiZv

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D3std3utf7__arrayZ

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D3std3utf12isValidDcharFNaNbNfwZb

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D3std3utf12UTFException6__ctorMFAyakAyakC6object9Th
 rowableZC3std3utf12UTFException

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D3std3utf12UTFException7__ClassZ

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined __adDupT

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D14TypeInfo_Array6__vtblZ

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D10TypeInfo_a6__initZ

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D14TypeInfo_Const6__vtblZ

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D9Exception7__ClassZ

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D3std9exception7bailOutFNaNfAyakxAaZv

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D3std5ascii7isDigitFNaNbNfwZb

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D6object9Exception6__ctorMFNaNbNfAyaAyakC6object9Th
 rowableZC9Exception

C:\Users\Aaron\AppData\Local\Temp\.rdmd\rdmd-test.d-AB3FF68B659C1090C52A7CFC868F
8061\objs\test.obj(test)
 Error 42: Symbol Undefined _D3std5array12__ModuleInfoZ
OPTLINK : Warning 134: No Start Address
--- errorlevel 41

这次我做错了什么?:P

4

1 回答 1

2

代码没有错误。
除了它没有main功能,因此您无法运行已编译的程序。您可以要求编译器main为您添加功能。只需使用-main开关。

rdmd是一个DMD 脚本外壳
您会收到错误,因为rdmd将文件名之后的所有参数都视为程序的开关。试试rdmd --main test.d

于 2013-05-31T22:00:36.747 回答