在 solaris 10 上编译 gtk 2.4 示例代码时出错

Error compiling gtkmm2.4 sample code on solaris10

尝试在我的 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 在我的系统的包管理器中只有一个。

不确定到哪里可以进一步解决此问题。任何建议。

通过进行以下更改解决了该问题:

我使用以下命令为我的 Solaris 系统安装了最新的 g++:

> /opt/csw/bin/pkgutil -a | grep g++
gcc4g++              CSWgcc4g++           4.9.2,REV=2014.11.07        41.9 MB
gcc5g++              CSWgcc5g++           5.2.0,REV=2015.07.31        57.2 MB
> /opt/csw/bin/pkgutil -i -y gcc5g++

它在 /opt/csw/gcc5/bin/ 目录中安装了一些库和新的 g++。 现在,我没有使用 Sun Solaris 编译器,而是使用了这个新的 g++ 编译器,一切正常。

但在使用 g++ 编译之前,我必须设置 LD_LIBRARY_PATH 如下:

setenv LD_LIBRARY_PATH /opt/csw/lib

与新的 g++ 编译器一样,还下载了一些库,这些库放在上面的目录中。

耶耶耶。 :)