
您好,我正在嘗試從原始程式碼編譯 gnome-packagekit git://git.gnome.org/gnome-packagekit
,當我嘗試時,make
出現上述錯誤
error: ‘g_type_init’ is deprecated (declared at /usr/local/include/glib-2.0/gobject/gtype.h:669) [-Werror=deprecated-declarations]
cc1: all warnings being treated as errors
我查了一下,似乎是因為 glib-2.35.4 已棄用該g_type_init
呼叫。 (我實際上不知道這意味著什麼)。wperror
據一些評論員稱,這似乎也與檢查有關。的輸出autogen.sh
是
gnome-packagekit 3.7.6
=============================
prefix: /usr/local
compiler: gcc
cflags: -g -O2
cppflags: -Werror -Wall -Wreturn-type -Wdeclaration-after-statement -Wno-uninitialized -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Winline -Wformat-nonliteral -Wformat-security -Wswitch-default -Winit-self -Wmissing-include-dirs -Wno-strict-aliasing -Wundef -Waggregate-return -Wmissing-format-attribute -g -fexceptions gnome-packagekit 3.7.6
=============================
prefix: /usr/local
compiler: gcc
cflags: -g -O2
cppflags: -Werror -Wall -Wreturn-type -Wdeclaration-after-statement -Wno-uninitialized -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Winline -Wformat-nonliteral -Wformat-security -Wswitch-default -Winit-self -Wmissing-include-dirs -Wno-strict-aliasing -Wundef -Waggregate-return -Wmissing-format-attribute -g -fexceptions
這表明這可能與此有關。
想知道是否有簡單的方法來告訴編譯器使用舊版本glib
或忽略werror
檢查。
答案1
(其實我也不知道什麼意思)
這意味著從 glib 版本 2.35.0 開始,不應再使用函數 g_type_init,因為目的是在將來的某個時候將其從庫中刪除。
因此,當針對 glib 版本 2.35.0 或更高版本編譯較舊的 glib 程式時,您應該編輯程式碼以圍繞 g_type_init 進行測試
#if !GLIB_CHECK_VERSION(2,35,0)
g_type_init ();
#endif
乍一看,g_type_init 似乎只會在 glib 2.35.0 中被排除,但巨集 LIB_CHECK_VERSION 實際上被定義為與指定版本相同或更高/更新的版本傳回 true。
我不知道是否有簡單的方法可以告訴編譯器使用舊版的 glib
您可以指示編譯器和連結器使用預設版本的較舊或較新版本,但顯然您需要安裝該版本,這很可能會導致其他程式嘗試使用錯誤版本的 glib 函式庫時出現問題。
因此,作為一般規則,僅安裝多個版本的庫作為最後的手段,特別是對於通用庫,例如被許多程式使用的 glib。
忽略錯誤檢查。
gcc 指令上的 -Wall 標誌告訴 gcc 標記所有警告,幾年來,gcc 的預設狀態是將所有警告視為錯誤。如果您在許多網站上問這個問題,回覆者只會告訴您進行網路搜尋。
如果您查看 gcc 的手冊頁,您會發現處理已棄用函數的特定問題的最佳方法是添加
-Wno-deprecated-聲明
到 gcc 命令,以便忽略該命令並仍保持使用 -Wall 檢查所有其他警告的安全性
答案2
註解掉包含 的行g_type_init
。那應該可以解決問題。