无法使用 ICU 库进行编译 - 对 'u_strlen_3_6' 的 undefined reference

标签 c icu

尝试让 ICU 库与我的 C 程序一起工作,这样我就可以小写 UTF-8 字符串。这是重现编译错误的最小示例:

ma​​in.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unicode/ustring.h>

int main(int argc, char **argv)
{
  UChar test[100] = { 0x41, 0x42, 0x43, 0x20, 0xc6, 0xd8, 0xc5, 0x20, 0xc9, 0x20, 0xc8, 0x20, 0xd1, 0x20, 0xca, 0x20, 0xd6 };
  for (int i = 0; i < u_strlen(test); i++){
    printf("%d\n", i);
  }
}

Makefile

CC = gcc
CFLAGS = -g -O3 -std=c99
GNUCFLAGS = -g -O3 -std=gnu99 -lm

main: obj/main.o
    $(CC) $(CFLAGS) -o bin/main obj/main.o

obj/main.o: src/main.c
    $(CC) $(CFLAGS) -c src/main.c -o obj/main.o

编译器输出

gcc -g -O3 -std=c99 -o bin/main obj/main.o
obj/main.o: In function `main':
~/src/main.c:9: undefined reference to `u_strlen_3_6'
collect2: error: ld returned 1 exit status
Makefile:6: recipe for target 'main' failed
make: *** [main] Error 1

我尝试包含 http://icu-project.org/apiref/icu4c/ 中列出的所有头文件没有运气。还尝试将 -licudata -licui18n -licuio -liculx -licutest -licutu -licuuc 添加到 Makefile - 同样的错误。

我使用的是 Debian GNU/Linux 8.5 (jessie),并且安装了以下软件包:

  • libicu52
  • libicu52-dbg
  • libicu-dev
  • icu-开发工具

有什么建议吗?

最佳答案

我认为你需要#include <unicode/utypes>.但是您应该能够通过搜索头文件找到哪个包含 u_strlen_3_6 的定义来找出需要哪个 Unicode 包含文件。

您可能还需要在 makefile 中的 CFLAGS 参数中添加 -I。

关于无法使用 ICU 库进行编译 - 对 'u_strlen_3_6' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39021900/

相关文章:

qt5 - Qt 是在没有 ICU 支持的情况下构建的,WebKit 被禁用。 VS2012

c - 将一个元素重新添加到动态数组列表中(从内存中删除后)

c - 查找 POSIX 信号量上阻塞的任务数

c - if 语句中只有变量名意味着什么

c - 如何修复 ';' token 错误之前的预期标识符

c - 初始化变量和声明后立即赋值有区别吗?

php - ICU:音译然后删除所有非字母数字字符

ios - Xcode 错误 - 库未加载 :/usr/local/opt/icu4c/lib/libicui18n. 58.dylib 错误 134

c++ - 您能否访问 ICU MessageFormat 使用的 NumberFormatter

linux - 通过 icu 布局引擎计算字形