解決方案1:
在GCC編譯命令中加入-export-dynamic,如:
gcc test.c callbacks.c -o test `pkg-config --libs --cflags libglade-2.0 ` -export-dynamic
解決方案2:
在GCC編譯命令中使用pkg-config加入庫gmodule-export-2.0,如:
gcc test.c callbacks.c -o test `pkg-config --libs --cflags libglade-2.0 gmodule-export-2.0`
問題原因,以下是libglade說明裏的一段原話。
Note If you wish to autoconnect handlers defined in the main executable (not a shared library), you will need to pass a linker flag to export the executable's symbols for dynamic linking. This flag is platform specific, but libtool can take care of this for you. Just add -export-dynamic argument to your link flags, and libtool will convert it to the correct format. The easiest way to get the correct extra flags is to check for gmodule-export-2.0 with pkg-config.
疑問:爲什麼?
need to pass a linker flag to export the executable's symbols for dynamic linking
一種回答:
Libglade can also automatically connect signal handlers in the user interface. It does this by matching handler names specified in the glade file with symbols in the executable looked up with the gmodule library (this requires that
applications be linked with the --export-dynamic flag).