This is my code. I want to test function mbstowcs_s.
#include <stdio.h>
#include <wchar.h>
#include <stdlib.h>
#include <locale.h>
#include <assert.h>
int main()
{
char MultiByteStr[20] = "a中";
wchar_t WideByteStr[20];
printf("%s\n", MultiByteStr);
char* LocaleInfo = setlocale(LC_CTYPE, "");
printf("%s\n", LocaleInfo);
// required length of WideByteStr
size_t WideStrLen = 0;
mbstowcs_s(&WideStrLen, NULL, 0, MultiByteStr, 0);
assert(WideStrLen < 20);
mbstowcs_s(NULL, WideByteStr, 20, MultiByteStr, WideStrLen);
WideByteStr[WideStrLen] = L'\0';
wprintf(L"%ls\n", WideByteStr);
return 0;
}
I test this code on windows platform successfully, but failed on linux platform. Below is the error message.
test.c: In function ‘main’:
test.c:20:5: warning: implicit declaration of function ‘mbstowcs_s’ [-Wimplicit-function-declaration]
mbstowcs_s(&WideStrLen, NULL, 0, MultiByteStr, 0);
^
/tmp/ccqzP6HF.o: In function `main':
test.c:(.text+0x77): undefined reference to `mbstowcs_s'
test.c:(.text+0xc3): undefined reference to `mbstowcs_s'
collect2: error: ld returned 1 exit status