I have the following piece of code which uses ICU macros in order to determine UTF-8 string length:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unicode/utf.h>
size_t utf8_strlen( uint8_t* str, size_t length ) {
int32_t i = 0;
int32_t result = 0;
UChar32 cur;
while( i < length ) {
U8_NEXT( str, i, length, cur );
if( cur < 0 )
return -1;
result++;
}
return result;
}
However, when compiling and linking it as
cc `icu-config --ldflags` test.c
I get the following error:
/tmp/ccaVwSaO.o: In function `utf8_strlen':
test.c:(.text+0x141): undefined reference to `utf8_nextCharSafeBody_48'
collect2: ld returned 1 exit status
The command above expands to cc -ldl -lm -L/usr/lib -licui18n -licuuc -licudata -ldl -lm test.c, and libicuuc does have utf8_nextCharSafeBody_48 defined in it. Why does the linking error happen?
Try:
$ cc test.c $( icu-config --ldflags )
you typically need to list libraries last.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With