- 论坛徽章:
- 5
|
回复 12# FightForWin
还是你V5,include 绝对路径
==================for example===============
1)下载icu4c:wget http://download.icu-project.org/ ... icu4c-4_6_1-src.tgz
2)解包,编译,安装
2.1) ./configure --prefix=/opt/gtk3 --enable-icuio=no --enable-extras=no --enable-layout=no --enable-tests=no --enable-samples=no
用不到的功能disable了
2.2)make 然后 make install
3)配置环境
3.1)export PKG_CONFIG_PATH=/opt/gtk3/lib/pkgconfig
3.2)export LD_LIBRARY_PATH=/opt/gtk3/lib
/opt/gtk3请用configure时指定的 --prefix 替换
3.3)测试环境
pkg-config --cflags --libs icu-i18n 应该有如下输出:-I/opt/gtk3/include -L/opt/gtk3/lib -licui18n -licuuc -licudata
4)编写测试代码- #include <string.h>
- #include <unicode/utypes.h>
- #include <unicode/ucsdet.h>
- #include <unicode/ucnv.h>
- #include <unicode/ustring.h>
- int main (int argc, char *argv[])
- {
- UErrorCode status = U_ZERO_ERROR;
- UCharsetDetector *csd;
- const UCharsetMatch *match;
- const char *name;
- const char *text = "我的代码该怎样去引用 我编译安装好的icu库呢? 我编译错误一大堆。";
- csd = ucsdet_open (&status);
- ucsdet_setText (csd, text, strlen (text), &status);
- if (U_FAILURE(status))
- {
- fprintf(stderr, "error: %s\n", u_errorName (status));
- ucsdet_close (csd);
- return -1;
- }
- match = ucsdet_detect (csd, &status);
- if (!match)
- {
- fprintf(stderr, "detect failed\n");
- ucsdet_close (csd);
- return -1;
- }
-
- name = ucsdet_getName (match, &status);
- printf("detected coding: %s\n", name);
- ucsdet_close (csd);
- return 0;
- }
复制代码 5)编译(就这一个文件,犯不着makefile)
gcc -o test `pkg-config --cflags --libs icu-i18n` test.c
6)测试
./test 打印:detected coding: UTF-8
7)over |
|