当前位置: 首页 > 工具软件 > GNU Free Call > 使用案例 >

openwrt lede解决编译:error GNU libiconv not in use but included iconv.h is from libiconv

都建树
2023-12-01

1.lede 17.1.5

2. 工程中没有glib2 需要手动添加一个,所以我从其他版本中直接拷贝过来一份glib2的配置(glib2 版本2.44.1)

3.当编译的时候出现了,error GNU libiconv not in use but included iconv.h is from libiconv

从源码找出现error的位置如下:

  53 
  54 #if defined(USE_LIBICONV_GNU) && !defined (_LIBICONV_H)
  55 #error GNU libiconv in use but included iconv.h not from libiconv
  56 #endif
  57 #if !defined(USE_LIBICONV_GNU) && defined (_LIBICONV_H) \
  58      && !defined (__APPLE_CC__) && !defined (__LP_64__)
  59 #error GNU libiconv not in use but included iconv.h is from libiconv
  60 #endif

需要避免两种情况:

第一种: 需要满足 USE_LIBICONV_GNU ,即编译选项--with-libiconv=gnu  (no/gnu/native),且使用libiconv库

第二种: 需要满足即非USE_LIBICONV_GNU,即编译选项--with-libiconv=no, 且不使用libiconv库

下面来看我的glib2 Makefile:

  1 #
  2 # Copyright (C) 2007-2015 OpenWrt.org
  3 #
  4 # This is free software, licensed under the GNU General Public License v2.
  5 # See /LICENSE for more information.
  6 #
  7 
  8 include $(TOPDIR)/rules.mk
  9 
 10 PKG_NAME:=glib2
 11 PKG_VERSION:=2.44.1
 12 PKG_RELEASE:=1
 13 
 14 PKG_SOURCE:=glib-$(PKG_VERSION).tar.xz
 15 PKG_BUILD_DIR:=$(BUILD_DIR)/glib-$(PKG_VERSION)
 16 PKG_SOURCE_URL:=@GNOME/glib/2.44
 17 PKG_MD5SUM:=83efba4722a9674b97437d1d99af79db
 18 
 19 PKG_BUILD_DEPENDS:=glib2/host libpthread zlib libintl libffi
 20 HOST_BUILD_DEPENDS:=libintl/host libiconv/host libffi/host
 21 PKG_INSTALL:=1
 22 PKG_USE_MIPS16:=0
 23 
 24 PKG_FIXUP:=autoreconf
 25 
 26 HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/glib-$(PKG_VERSION)
 27 
 28 include $(INCLUDE_DIR)/host-build.mk
 29 include $(INCLUDE_DIR)/package.mk
 30 include $(INCLUDE_DIR)/nls.mk
 31 
 32 define Package/glib2
 33   SECTION:=libs
 34   CATEGORY:=Libraries
 35   DEPENDS:=$(ICONV_DEPENDS) $(INTL_DEPENDS) +zlib +libpthread +libffi +libattr
 36   TITLE:=glib 2.0
 37   MAINTAINER:=Peter Wagner <tripolar@gmx.at>
 38   URL:=http://www.gtk.org/
 39 endef
 40 
 41 define Package/glib2/description
 42   The GLib library of C routines
 43 endef
 44 
 45 HOST_CONFIGURE_ARGS += \
 46     --disable-selinux
 47 
 48 CONFIGURE_ARGS += \
 49     --enable-shared \
 50     --enable-static \
 51     --enable-debug=no \
 52     --disable-selinux \
 53     --disable-fam \
 54     $(if $(ICONV_FULL),--with-libiconv=gnu)
 55 
 56 CONFIGURE_VARS += \
 57     glib_cv_stack_grows=no \
 58     glib_cv_uscore=no \
 59     ac_cv_path_GLIB_GENMARSHAL=$(STAGING_DIR_HOST)/bin/glib-genmarshal \
 60     ac_cv_func_mmap_fixed_mapped=yes \
 61     ac_cv_func_posix_getpwuid_r=yes \
 62     ac_cv_func_posix_getgrgid_r=yes
 63 
 64 define Build/InstallDev
 65     $(INSTALL_DIR) $(1)/usr/include
 66     $(CP) \
 67         $(PKG_INSTALL_DIR)/usr/include/glib-2.0 \
 68         $(1)/usr/include/
 69     $(CP) \
 70         $(PKG_INSTALL_DIR)/usr/lib/glib-2.0/include/*.h \
 71         $(1)/usr/include/glib-2.0/
 72     $(CP) \
 73         $(PKG_INSTALL_DIR)/usr/include/gio-unix-2.0 \
 74         $(1)/usr/include/
 75 
 76     $(INSTALL_DIR) $(1)/usr/lib
 77     $(CP) \
 78         $(PKG_INSTALL_DIR)/usr/lib/glib-2.0 \
 79         $(1)/usr/lib/
 80 
 81     $(CP) \
 82         $(PKG_INSTALL_DIR)/usr/lib/*.{so*,a,la} \
 83         $(1)/usr/lib/
 84 
 85     $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
 86     $(INSTALL_DATA) \
 87         $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/*.pc \
 88         $(1)/usr/lib/pkgconfig
 89 
 90     $(INSTALL_DIR) $(2)/share/aclocal/
 91     $(INSTALL_DATA) \
 92         $(PKG_INSTALL_DIR)/usr/share/aclocal/*.m4  \
 93         $(2)/share/aclocal/
 94 endef
 95 
 96 define Package/glib2/install
 97     $(INSTALL_DIR) $(1)/usr/lib
 98     $(CP) \
 99         $(PKG_INSTALL_DIR)/usr/lib/*.so* \
100         $(1)/usr/lib/
101 endef
102 
103 $(eval $(call HostBuild))
104 $(eval $(call BuildPackage,glib2))

重点看:  
 48 CONFIGURE_ARGS += \
 49     --enable-shared \
 50     --enable-static \
 51     --enable-debug=no \
 52     --disable-selinux \
 53     --disable-fam \
 54     $(if $(ICONV_FULL),--with-libiconv=gnu)
 ICONV_FULL 代表一个libiconv-full的库,如果这个库选上,使用--with-libiconv=gnu选项

而ICONV_FULL怎么选:则看openwrt 目录中include/nls.mk

  8 # iconv full
  9 ifeq ($(CONFIG_BUILD_NLS),y)
 10     ICONV_PREFIX:=$(STAGING_DIR)/usr/lib/libiconv-full
 11     ICONV_FULL:=1
 12 
 13     INTL_PREFIX:=$(STAGING_DIR)/usr/lib/libintl-full
 14     INTL_FULL:=1

 15 
 16 # iconv stub
 17 else
 18     ICONV_PREFIX:=$(STAGING_DIR)/usr/lib/libiconv-stub
 19     ICONV_FULL:=
 20 
 21     INTL_PREFIX:=$(STAGING_DIR)/usr/lib/libintl-stub
 22     INTL_FULL:=
 23 endif

从这个配置中可以看出,只需要选择编译选项CONFIG_BUILD_NLS即可.

make menuconfig

       --->Global build settings

                 ----->[*] Compile with full language support

另外还需要加上libiconv的库

 ---->Libraries

              ---------><*> libintl-full............................ GNU Internationalization library

保存配置,这样就大功告成了

这样的配置编译target是没有问题,我的工程在编译hostbuild的有问题,于是乎我在hostbuild中加了两项的配置:

 45 HOST_CONFIGURE_ARGS += \
 46     --disable-selinux \

 47     --prefix=$(STAGING_DIR_HOST) \            //将生成的二进制,安装到host目录(我的工程默认安装,安装位置有问题)
 48     --exec-prefix=$(STAGING_DIR_HOST) \

 47     $(if $(ICONV_FULL),--with-libiconv=gnu) \   (host也有这个问题,所以也加上了)
 48     ac_cv_path_GLIB_GENMARSHAL=$(STAGING_DIR_HOST)/bin/glib-genmarshal   (这个如果不加,可能会找不到glib-genmarshal)

这要的改变,可以在工程完美编译通过.最终可以在:staging_dir/target****/usr/lib看到生成的glib2的库.

libiconv库 为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换。

 类似资料: