当我们在使用Window操作系统的时候,可能使用最多的文本格式就是txt了,可是当我们将Window平台下的txt文本文档复制到Linux平台下查看时,发现原来的中文所有变成了乱码。
3. 命令学习
该工具安装完毕后,肯定要先了解下这个命令的使用方法吧。这个没什么可说的:
iconv -f 原编码 -t 目标编码 要转换的文件
4. 编码转换:
学会了编码的转化。我们就举了样例示范一下:
注意:
假设不出意外的话。上面的安装步骤可没有那么顺利。在make的时候,会提示以下的错误:
那我们仅仅要进行例如以下操作就可以解决问题:
1. 切换到srclib文件夹下:
3. 保存退出。然后再进行make, make install便可顺利安装^-^
參考资料:http://forum.z27315.com/topic/15662-%E8%A7%A3%E5%86%B3%E7%BC%96%E8%AF%91libiconv%E6%97%B6%E7%9A%84gets-undeclared-here%E9%94%99%E8%AF%AF/
没错, 引起这个结果的原因就是两个平台下,编辑器对默认的编码格式是不一样的:
 在Window平台下。Notepad的默认编码是ASCII码或者GBK,而在Linux平台下默认的是UTF-8(中文环境的情况),编码的不同导致了原来文档中的中文变成了乱码。
 解决的方法:
 使用iconv命令将文档的编码进行转换就可以。
 iconv默认情况下,是没有被安装的。以下简介下iconv的安装过程:
 1. 下载:
http://www.gnu.org/software/libiconv/#TOCdownloading
 2. 安装:
 下载完毕后,切换到下载文件夹先进行解压:
$tar -xzvf libiconv-1.14.tar.gz然后进入解压后的文件里
$cd libiconv-1.14_2$ ./configure --prefix=/usr/local
$ make
$ make install3. 命令学习
该工具安装完毕后,肯定要先了解下这个命令的使用方法吧。这个没什么可说的:
$iconv --helpUsage: iconv [OPTION...] [FILE...]
Convert encoding of given files from one encoding to another.Input/Output format specification:-f, --from-code=NAME       encoding of original text-t, --to-code=NAME         encoding for outputInformation:-l, --list                 list all known coded character setsOutput control:-c                         omit invalid characters from output-o, --output=FILE          output file-s, --silent               suppress warnings--verbose              print progress information-?, --help Give this help list --usage Give a short usage message -V, --version Print program version Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options.
说的非常明确,就是依照以下的格式进行转换:iconv -f 原编码 -t 目标编码 要转换的文件
4. 编码转换:
学会了编码的转化。我们就举了样例示范一下:
$iconv -f gbk -t utf8 test.txt$iconv -f gbk -t utf8 test.txt -o test$iconv -f gbk -t utf8 test.txt < test注意:
假设不出意外的话。上面的安装步骤可没有那么顺利。在make的时候,会提示以下的错误:
n file included from progname.c:26:0:
./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function)_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");^
make[2]: *** [progname.o] Error 1
make[2]: Leaving directory `/home/freeman/Downloads/libiconv-1.14_2/srclib'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/freeman/Downloads/libiconv-1.14_2/srclib'
make: *** [all] Error 2--- srclib/stdio.in.h.orig      2011-08-07 16:42:06.000000000 +0300
+++ srclib/stdio.in.h   2013-01-10 15:53:03.000000000 +0200
@@ -695,7 +695,9 @@/* It is very rare that the developer ever has full control of stdin,so any use of gets warrants an unconditional warning.  Assume it isalways declared, since it is required by C89.  */
-_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
+#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
+ _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
+#endif#endif那我们仅仅要进行例如以下操作就可以解决问题:
1. 切换到srclib文件夹下:
$cd srclib2. 改动stdio.in.h文件:
$gedit stdio.in.h#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif3. 保存退出。然后再进行make, make install便可顺利安装^-^
參考资料:http://forum.z27315.com/topic/15662-%E8%A7%A3%E5%86%B3%E7%BC%96%E8%AF%91libiconv%E6%97%B6%E7%9A%84gets-undeclared-here%E9%94%99%E8%AF%AF/