D book的例子不起作用,奇怪的错误

时间:2013-05-31 21:01:56

标签: 64-bit d 16-bit xamarin-studio dmd

全部,

我正在使用Xamarin Studio 4.08和Mono-D使用DMD2编译器对D进行编程。当我尝试编译以下内容时(来自The D Programming Language - Alexandrescu,2010-第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));时,情节会变浓,因为这会产生一个非常奇怪的错误:

lolwtfbbqsauce

首先,缺少一个库,然后,它是一个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

1 个答案:

答案 0 :(得分:2)

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

rdmdDMD Script Shell 您会收到错误,因为rdmd将文件名后的所有参数视为程序的开关。试试rdmd --main test.d