我的項目有一個清理終端的函數,它使用curses庫實現。編譯與-lcurses
標誌工作正常,但沒有yeilds你可以在C++中處理編譯時錯誤嗎?
/tmp/cc3T2MVI.o: In function `ClearScreen()':
clear_term.cpp:(.text+0xb): undefined reference to `cur_term'
clear_term.cpp:(.text+0x26): undefined reference to `setupterm'
clear_term.cpp:(.text+0x37): undefined reference to `tigetstr'
clear_term.cpp:(.text+0x3f): undefined reference to `putp'
collect2: ld returned 1 exit status
這顯然是預期的,因爲它不能找到庫編譯,但由於此功能是補充最好將定義ClearScreen()
作爲一個空函數,而不是有編譯失敗。我知道我把函數定義放在一個#ifdef
塊中,但我不知道由curses定義的任何標誌。
是否有可能捕獲這些錯誤,而是將ClearScreen()
定義爲空函數?
這實際上是一個鏈接器錯誤,而不是編譯器錯誤。一個C++編譯器通常生成一個'.o'(或'.obj')文件,鏈接器會收集所有'.o'文件以形成庫(動態或靜態)或可執行文件。 – 2012-02-28 18:42:37