2014-02-05 105 views
2

我正在爲自己寫一個庫,以幫助自動執行一些我在D中用於從命令行執行腳本的常見任務。作爲參考,在這裏被全部代碼:D:dmd說一些真奇怪的東西

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),我得到這個錯誤信息:

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,如果有幫助的話。

+0

警告134意味着你正在編譯爲一個應用程序而不是庫 –

回答

4

這些錯誤消息來自OPTLINK,鏈接器D用於編譯32位Windows程序。

如果您試圖將庫編譯爲.lib文件,則需要在編譯後使用-lib編譯器開關調用庫管理器(而不是鏈接器)。 (技術上DMD的圖書管理員被內置到編譯器,因此它直接發射.lib。)

如果你只打算編譯一個模塊到一個.obj文件,使用-c選項禁止調用鏈接。

如果未指定-lib-c,那麼DMD將在編譯後調用鏈接器,該鏈接器將嘗試將源文件構建爲可執行程序。如果您的源文件都不包含入口點(main函數),則鏈接器將抱怨「無起始地址」。

如果您試圖構建一個使用您的庫的程序,並且只在調試模式下收到鏈接錯誤,則可能表示鏈接程序找不到標準庫的調試版本。該設置使用-debuglib開關指定,通常與非調試庫(也可以使用-defaultlib開關指定)相同。

+0

我認爲通常最簡單(最好)只是將所有文件編譯在一起,所以'dmd mainfile.d otherfile.d helperfile.d commontasks。這樣可以避免單獨庫構建的麻煩,並且通常比單獨構建它們更快(它可以緩存導入表並同時執行其他文件) –