简体   繁体   English

如何在没有libiconv符号名称的情况下在OSX上构建iconv的静态库?

[英]How to build a static lib of iconv on OSX without libiconv symbol names?

I am trying to build gnu iconv on OSX as a static library. 我正在尝试在OSX上将gnu iconv构建为静态库。 This is not a problem, it builds fine with 这不是问题,它可以很好地构建

./configure --enable-static
make clean && make

but when I run nm on libiconv.a, I get the following results 但是当我在libiconv.a上运行nm时,得到以下结果

...
_libiconv
_libiconv_open_
_libiconv_close_
...

This is problematic, because I want to build libxml2 using this library, and it requires the following symbols 这是有问题的,因为我想使用此库来构建libxml2,并且它需要以下符号

iconv
iconv_open
iconv_close

Looking through the header file, it seems like the difference between these two symbol names is whether LIBICONV_PLUG is defined. 浏览头文件时,似乎这两个符号名称之间的区别在于是否定义了LIBICONV_PLUG。 But when I run make as 但是当我运行make as

make clean && make CPPFLAGS=-DLIBICONV_PLUG

I get errors because several things are not defined, such as ICONV_GET_DISCARD_ILSEQ and ICONV_SET_HOOKS. 我收到错误消息是因为未定义一些内容,例如ICONV_GET_DISCARD_ILSEQ和ICONV_SET_HOOKS。 Looking through the header file again, these are only defined if LIBICONV_PLUG is not defined. 再次浏览头文件,只有在未定义LIBICONV_PLUG的情况下才定义它们。

My question is, am I using LIBICONV_PLUG correctly? 我的问题是,我是否正确使用LIBICONV_PLUG? Is there some other way to get a static library with the symbols I need? 还有其他方法来获取带有所需符号的静态库吗? Should I go through the undefined symbols and define them myself by hand? 我是否应该浏览未定义的符号并自己手动定义它们?

There are three possible ways to build and use GNU libiconv. 有三种可能的方式来构建和使用GNU libiconv。 In all three cases, the symbols that it defines for use by a C or C++ program (through the header file) are 'iconv_open', 'iconv', 'iconv_close'. 在所有三种情况下,它定义供C或C ++程序使用(通过头文件)的符号是'iconv_open','iconv','iconv_close'。

  • The normal one is that, at object file level, it defines symbols 'libiconv_open' etc., so as not to conflict with the operating system's standard libraries. 通常的做法是,在目标文件级别上,它定义符号“ libiconv_open”等,以免与操作系统的标准库冲突。 The mapping between the symbol at C level and at object file level happens in <iconv.h>. C级别和目标文件级别的符号之间的映射发生在<iconv.h>中。

    You will get a link error if you use the system's <iconv.h> with the GNU libiconv.{so,dylib,a} or vice versa. 如果将系统的<iconv.h>与GNU libiconv一起使用,则会出现链接错误。{so,dylib,a},反之亦然。 This is a feature, because the two have slightly different features (OS X libiconv.dylib supports an encoding named "UTF-8-MAC", whereas GNU libiconv has a number of improvements and fixes) and mismatch can lead to trouble. 这是一个功能,因为两者具有略有不同的功能(OS X libiconv.dylib支持名为“ UTF-8-MAC”的编码,而GNU libiconv具有许多改进和修复),并且不匹配会导致麻烦。

  • If you are a system vendor, you can build GNU libiconv in such a way that it defines 'iconv_open' instead of 'libiconv_open', etc. This is achieved through a simple edit of iconv.h. 如果您是系统供应商,则可以以定义“ iconv_open”而不是“ libiconv_open”等的方式构建GNU libiconv。这可以通过对iconv.h的简单编辑来实现。

    Or, specifically on OS X, you can pick the libiconv from https://opensource.apple.com/ and compile it for yourself. 或者,特别是在OS X上,您可以从https://opensource.apple.com/选择libiconv并自己编译。 But be aware that this version is based on GNU libiconv 1.11, that is, it is quite old. 但是请注意,此版本基于GNU libiconv 1.11,也就是说,它已经很旧了。

  • As explained in GNU libiconv's README, the LIBICONV_PLUG flag creates a library that will override the functionality in the system; 如GNU libiconv的README中所述,LIBICONV_PLUG标志创建一个库,该库将覆盖系统中的功能。 this works only on GNU, Solaris, and OSF/1. 这仅适用于GNU,Solaris和OSF / 1。

In your case, where you only want to have GNU libiconv be used by some free software package (such as libxml2), the simplest way is to take the first approach, and during compilation of that package, use -I and -L options to make it find the GNU libiconv header file and library. 在您的情况下,您只想让某些免费软件包(例如libxml2)使用GNU libiconv,最简单的方法是采用第一种方法,并且在编译该软件包时,请使用-I和-L选项使它找到GNU libiconv头文件和库。

In fact, libxml2 makes this easy: its configure script already has an option --with-iconv= prefix , through which you specify the directory hierarchy in which you have installed GNU libiconv (the header file in prefix /include/ and the object file in prefix /lib/); 实际上,libxml2使得此操作变得容易:它的配置脚本已经具有--with-iconv = prefix选项,通过该选项可以指定安装GNU libiconv的目录层次结构( 前缀 / include /中的头文件和目标文件)在前缀 / lib /)中; the configure script will then synthesize the appropriate -I and -L options. 然后,配置脚本将合成适当的-I和-L选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM