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