2014-11-02 70 views
0

我目前有這樣的使G ++點這個錯誤/警告了

std::string student::returnData() 
{ 
    // return "This is return type" ; 
    std::cout << "Hello World"; 
} 

一份聲明然而,當我建立了C++項目作爲這樣

entry: main.o student.o 
     g++ -W -Wall -Werror -o [email protected] main.o student.o 

main.o: 
    g++ -W -Wall -Werror -c main.cpp 

clean: 
     rm -rf *.o entry 

我不是給予警告/錯誤,當這種方法執行輸出開始瘋狂 任何建議,我可以做什麼,所以我可以得到像這樣的愚蠢的錯誤警告

+1

您是否在製作過程中將錯誤重定向到某些文件? – P0W 2014-11-02 06:29:02

+0

你是否有'student.o'的規則,或者你在使用隱式規則嗎? – juanchopanza 2014-11-02 06:49:11

+0

不,我沒有學生規則.o – Rajeshwar 2014-11-02 06:50:25

回答

2

gcc會發出一個錯誤標誌-Wall -Werror。問題是您沒有針對目標student.o的規則,並且隱式規則不使用任何警告標誌。最簡單的方法可能是全局設置警告標誌,並讓隱式規則執行它們的操作。這可以通過使用CXXFLAGS變量(或CFLAGS的C代碼)來實現:

CXXFLAGS += -Wall -Werror 

這會照顧student.o並沒有一個明確的規則,任何.o。請注意,此規則使student.o隱含依賴於student.cpp,student.cc or student.C。您可以添加的依賴,而無需修改食譜是這樣的:

student.o: student.h # student.o now depends on student.h too 

這將導致形式

error: no return statement in function returning non-void [-Werror=return-type]

我建議增加Wextra警告標誌的錯誤。