nginx upload 模組build錯誤解決error: variable ‘result’ set but not used [-Werror=unused-but-set-variable]

pengfoo發表於2013-10-17

../nginx_upload_module-2.2.0/ngx_http_upload_module.c: In function ‘ngx_http_upload_merge_ranges’:../nginx_upload_module-2.2.0/ngx_http_upload_module.c:1681:18: error: variable ‘result’ set but not used [-Werror=unused-but-set-variable]cc1: all warnings being treated as errorsmake[1]: *** [objs/addon/nginx_upload_module-2.2.0/ngx_http_upload_module.o] Error 1make[1]: Leaving directory `/root/build/nginx-1.0.10'make: *** [build] Error 2

解決:

Just replace "int result;" by "__attribute__((__unused__)) int result;".

 

分析:程式碼中有類似這樣的程式碼

 

int main()

{

  int result;

  if(...)

  {result = func();

  }

}

編譯器檢查嚴格,把所有的警告當做錯誤來對待。該警告產生的原因是由於 result有可能定義了但是用不到(if不會執行)

相關文章