在我的 Solaris10 机器上尝试编译 gtkmm 示例代码时,我在 glibmm/variant.h 头文件中遇到了一些编译时错误。
系统配置如下:
> uname -a
> SunOS selix570bx 5.10 Generic_150401-04 i86pc i386 i86pc
编译器版本如下:
> CC -V
> CC: Sun C++ 5.8 2005/10/13
源代码(sample.cc)如下:
#include <gtkmm.h>
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Gtk::Window window;
Gtk::Main::run(window);
return 0;
}
编译源码的命令如下:
> CC -library=stlport4 sample.cc -o sample `pkg-config gtkmm-2.4 --cflags --libs`
pkg-config 命令的输出如下供参考:
> pkg-config gtkmm-2.4 --cflags --libs
> -I/opt/csw/include/gtkmm-2.4 -I/opt/csw/lib/gtkmm-2.4/include -I/opt/csw/include/atkmm-1.6 -I/opt/csw/include/giomm-2.4 -I/opt/csw/lib/giomm-2.4/include -I/opt/csw/include/pangomm-1.4 -I/opt/csw/lib/pangomm-1.4/include -I/opt/csw/include/gtk-2.0 -I/opt/csw/include/gtk-unix-print-2.0 -I/opt/csw/include/gdkmm-2.4 -I/opt/csw/lib/gdkmm-2.4/include -I/opt/csw/include/atk-1.0 -I/opt/csw/include/glibmm-2.4 -I/opt/csw/lib/glibmm-2.4/include -I/opt/csw/include/glib-2.0 -I/opt/csw/lib/glib-2.0/include -I/opt/csw/include/sigc++-2.0 -I/opt/csw/lib/sigc++-2.0/include -I/opt/csw/include/cairomm-1.0 -I/opt/csw/lib/cairomm-1.0/include -I/opt/csw/include/pango-1.0 -I/opt/csw/include/cairo -I/opt/csw/lib/gtk-2.0/include -I/opt/csw/include/gdk-pixbuf-2.0 -I/opt/csw/include/freetype2 -I/opt/csw/include -L/opt/csw/lib -lgtkmm-2.4 -latkmm-1.6 -lgdkmm-2.4 -lgiomm-2.4 -lpangomm-1.4 -lgtk-x11-2.0 -lglibmm-2.4 -lcairomm-1.0 -lsigc-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0 -lintl
以下是我在编译示例 gtkmm 代码时遇到的错误:
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1277: Error: Glib::Variant<Glib::T>::Variant() is not a member of Glib::Variant<Glib::T>.
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1283: Error: Multiple declaration for<no tag>.
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1296: Error: Templates can only declare classes or functions.
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1300: Error: A declaration was expected instead of "return".
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1301: Error: A declaration was expected instead of "}".
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1304: Error: Templates can only declare classes or functions.
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1307: Error: A declaration was expected instead of "return".
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1307: Error: Template Variant is not defined.
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1308: Error: A declaration was expected instead of "}".
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1314: Error: Templates can only declare classes or functions.
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1320: Error: A declaration was expected instead of "return".
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1321: Error: A declaration was expected instead of "}".
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1324: Error: Templates can only declare classes or functions.
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1328: Error: Multiple declaration for Variant.
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1328: Error: Template Variant is not defined.
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1330: Error: Multiple declaration for Variant.
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1330: Error: Template Variant is not defined.
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1330: Error: Use ";" to terminate declarations.
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1330: Error: A declaration was expected instead of ",".
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1330: Error: "," expected instead of ">".
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1330: Error: Use ";" to terminate declarations.
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1330: Error: A declaration was expected instead of ",".
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1330: Error: Multiple declaration for V.
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1330: Error: "," expected instead of ">".
"/opt/csw/include/glibmm-2.4/glibmm/variant.h", line 1333: Error: A declaration was expected instead of "return".
Compilation aborted, too many Error messages.
早些时候,我收到了更多的错误消息,包括上述错误,但大多数错误通过包含 -library=stlport4 就消失了。
现在,这些错误是因为我的编译器不支持 c++11,因为我在旧的 solaris10 系统上。但我选择 gtkmm2.4 因为我认为它也适用于旧版本的 C++ 编译器。我还尝试检查是否使用更新版本的 glibmm。但是当前安装的 glibmm 仅在我的系统的包管理器中可用。
不确定在哪里可以进一步解决此问题。有什么建议么。