Ubuntu下配置wxWidgets始终提示‘未找到GTK+开发文件’错误
配置wxWidgets时无法定位GTK+开发文件的解决办法
问题背景
在Ubuntu系统中执行以下configure命令配置wxWidgets时,始终提示“未找到GTK+开发文件”,即使已安装所有GTK相关软件包,配置程序仍无法定位到GTK:
./configure --with-regex=builtin --with-gtk --enable-unicode --disable-shared --prefix=/usr/local/wxWidgets
错误日志
./configure --with-regex=builtin --with-gtk --enable-unicode --disable-shared --prefix=/usr/local/wxWidgets checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking for toolkit... gtk checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking whether we are using the Intel C compiler... no checking how to run the C preprocessor... gcc -E checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking whether gcc needs -traditional... no checking for g++... g++ checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking whether we are using the Intel C++ compiler... no checking whether we are using the Sun C++ compiler... no checking for ar... ar checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for langinfo.h... yes checking for wchar.h... yes checking for sys/select.h... yes checking for cxxabi.h... yes checking for an ANSI C-conforming const... yes checking for inline... inline checking size of short... 2 checking size of void *... 8 checking size of int... 4 checking size of long... 8 checking size of size_t... 8 checking size of long long... 8 checking size of wchar_t... 4 checking for va_copy... yes checking for _FILE_OFFSET_BITS value needed for large files... 64 checking if large file support is available... yes checking for _LARGEFILE_SOURCE value needed for large files... no checking whether byte ordering is bigendian... no checking for std::wstring in <string>... yes checking for std::istream... yes checking for std::ostream... yes checking for type_traits... yes checking for __sync_xxx_and_fetch builtins... yes checking for libraries directories... /usr/lib/x86_64-linux-gnu /usr/lib checking for cos... no checking for floor... no checking if floating point functions link without -lm... no checking for sin... yes checking for ceil... yes checking if floating point functions link with -lm... yes checking for strtoull... yes checking for pkg-config... /usr/bin/pkg-config checking pkg-config is at least version 0.9.0... yes checking whether pcre submodule exists... yes checking for zlib.h >= 1.1.4... yes checking for zlib.h... (cached) yes checking for deflate in -lz... yes checking for png.h > 0.90... yes checking for png.h... (cached) yes checking for png_sig_cmp in -lpng... yes checking for jpeglib.h... yes checking for jpeg_read_header in -ljpeg... yes checking for jbg_dec_init in -ljbig... yes checking for LIBTIFF... yes checking for expat.h... yes checking if expat.h is valid C++ header... yes checking for XML_ParserCreate in -lexpat... yes checking for LIBCURL... yes checking for GTK+ version... checking for pkg-config... (cached) /usr/bin/pkg-config checking pkg-config is at least version 0.16... yes checking for GTK+ - version >= 3.0.0... no *** Could not run GTK+ test program, checking why... *** The test program failed to compile or link. See the file config.log for the *** exact error that occurred. This usually means GTK+ is incorrectly installed. checking for pkg-config... (cached) /usr/bin/pkg-config checking pkg-config is at least version 0.7... yes checking for GTK+ - version >= 2.6.0... no *** Could not run GTK+ test program, checking why... *** The test program failed to compile or link. See the file config.log for the *** exact error that occured. This usually means GTK+ is incorrectly installed. checking for pkg-config... /usr/bin/pkg-config checking for GTK+ - version >= 3.90.0... Package gtk4 was not found in the pkg-config search path. Perhaps you should add the directory containing `gtk4.pc' to the PKG_CONFIG_PATH environment variable No package 'gtk4' found no *** Could not run GTK+ test program, checking why... *** The test program failed to compile or link. See the file config.log for the *** exact error that occurred. This usually means GTK+ is incorrectly installed. checking for gtk-config... no checking for GTK - version >= 1.2.7... no *** The gtk-config script installed by GTK could not be found *** If GTK was installed in PREFIX, make sure PREFIX/bin is in *** your path, or set the GTK_CONFIG environment variable to the *** full path to gtk-config. checking for gtk-config... (cached) no checking for GTK - version >= 1.2.3... no *** The gtk-config script installed by GTK could not be found *** If GTK was installed in PREFIX, make sure PREFIX/bin is in *** your path, or set the GTK_CONFIG environment variable to the *** full path to gtk-config. configure: error: The development files for GTK+ were not found. For GTK+ 2, please ensure that pkg-config is in the path and that gtk+-2.0.pc is installed. For GTK+ 1.2 please check that gtk-config is in the path, and that the version is 1.2.3 or above. Also check that the libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config --libs' are in the LD_LIBRARY_PATH or equivalent.
排查与解决步骤
针对性安装GTK开发包
不要笼统安装所有GTK包,根据wxWidgets的检测逻辑安装对应版本:# 安装GTK3开发包 sudo apt install libgtk-3-dev # 或安装GTK2开发包 sudo apt install libgtk2.0-dev验证pkg-config的识别能力
执行以下命令确认pkg-config能找到GTK:# 检查GTK3 pkg-config --cflags gtk+-3.0 pkg-config --libs gtk+-3.0 # 检查GTK2 pkg-config --cflags gtk+-2.0 pkg-config --libs gtk+-2.0若命令报错,检查
PKG_CONFIG_PATH环境变量是否包含GTK的.pc文件路径(通常在/usr/lib/x86_64-linux-gnu/pkgconfig/)。手动指定GTK版本
若自动检测失败,直接在configure命令中指定GTK版本:# 强制使用GTK3 ./configure --with-regex=builtin --with-gtk=3 --enable-unicode --disable-shared --prefix=/usr/local/wxWidgets # 强制使用GTK2 ./configure --with-regex=builtin --with-gtk=2 --enable-unicode --disable-shared --prefix=/usr/local/wxWidgets查看config.log定位细节错误
配置失败生成的config.log文件中,GTK检测部分会记录具体的编译/链接错误(比如缺失某个依赖库),根据日志补充安装对应的依赖即可。
内容的提问来源于stack exchange,提问作者junxi zhu
相关产品推荐
相关产品推荐

