Incorrect collate when linking with static

Mitja Špes <[email protected]>
Newsgroups gmane.linux.ports.arm.general
Message-ID <!&!AAAAAAAAAAAYAAAAAAAAAHwW0WbJwyhNsG/gnYbiZGrCgAAAEAAAAO13zj/[email protected]>
Hi all,

I'm trying to use locales for localized sorting but I stumbled across a
problem when compiling with '-static' flag.
If I use the static flag the sorting doesn't work correctly but it does so
if I compile with dynamic linking.

Testapp (look bellow) when compiled "arm-none-linux-gnueabi-gcc testapp.c -o
testapp" gives this output:
Locale set to sl_SI.utf8; Sorted: B C Ä (\xc4\x8c) D S Ĺ (\xc5\xa0)
This is the correct output.

Compiled with "arm-none-linux-gnueabi-gcc -static testapp.c -o testapp"
gives this output:
Locale set to sl_SI.utf8; Sorted: B C D S Ä (\xc4\x8c) Ĺ (\xc5\xa0)
Which is incorrect.

What am I doing wrong and how can I fix it so it will work with -static
compile?

Thank you for your help!

Mitja


------ testapp.c ------
#include <stdio.h>
#include <locale.h>

static int compare_ascii(const void *x, const void *y)
{
	return strcoll(*(char **)x, *(char **)y);
}

int main(int argc, char **argv)
{
	char *lines[]={ "S", "\xc4\x8c", "C", "B", "D", "\xc5\xa0" };
	int i, nlines = 6;

 	char *p=setlocale(LC_COLLATE|LC_CTYPE, "sl_SI.utf8");
 	if(!p) {
 	  printf("ERROR: Locale not set\r\n");
 	} else {
 	  printf("Locale set to %s\r\n",p);
 	}

	qsort(lines, nlines, sizeof(char *), compare_ascii);

	printf("Sorted:\r\n");
	for (i = 0; i < nlines; i++)
		puts(lines[i]);

	return 0;
}
---- end testapp.c ----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.