int main()
{
// UTF-8 narrow multibyte encoding
std::string data = reinterpret_cast<const char*>(+u8"z\u00df\u6c34\U0001f34c");
// or reinterpret_cast<const char*>(+u8"zß水🍌")
// or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9f\x8d\x8c"
std::ofstream("text.txt") << data;
// using system-supplied locale's codecvt facet
std::wifstream fin("text.txt");
// reading from wifstream will use codecvt<wchar_t, char, mbstate_t>
// this locale's codecvt converts UTF-8 to UCS4 (on systems such as Linux)
fin.imbue(std::locale("en_US.UTF-8"));
std::cout << "The UTF-8 file contains the following UCS4 code units: ";
for (wchar_t c; fin >> c; )
std::cout << "U+" << std::hex << std::setw(4) << std::setfill('0')
<< static_cast<uint32_t>(c) << ' ';
// using standard (locale-independent) codecvt facet
std::wstring_convert<
deletable_facet<std::codecvt<char16_t, char, std::mbstate_t>>, char16_t> conv16;
std::u16string str16 = conv16.from_bytes(data);
std::cout << "\nThe UTF-8 file contains the following UTF-16 code units: ";
for (char16_t c : str16)
std::cout << "U+" << std::hex << std::setw(4) << std::setfill('0')
<< static_cast<uint16_t>(c) << ' ';
}
Output is :
ppc-amigaos-g++ -mcrt=clib2 -athread=native test.cpp -o codecvt -lpthread -lz
/tmp/cc0nN0eZ.o: In function `_ZNSt7codecvtIDsc10_mbstate_tEC2Ej':
test.cpp:(.text._ZNSt7codecvtIDsc10_mbstate_tEC2Ej[_ZNSt7codecvtIDsc10_mbstate_tEC5Ej]+0x2e): undefined reference to `_ZTVSt7codecvtIDsc10_mbstate_tE'
test.cpp:(.text._ZNSt7codecvtIDsc10_mbstate_tEC2Ej[_ZNSt7codecvtIDsc10_mbstate_tEC5Ej]+0x32): undefined reference to `_ZTVSt7codecvtIDsc10_mbstate_tE'
/tmp/cc0nN0eZ.o: In function `_ZN15deletable_facetISt7codecvtIDsc10_mbstate_tEED2Ev':
test.cpp:(.text._ZN15deletable_facetISt7codecvtIDsc10_mbstate_tEED2Ev[_ZN15deletable_facetISt7codecvtIDsc10_mbstate_tEED5Ev]+0x30): undefined reference to `_ZNSt7codecvtIDsc10_mbstate_tED2Ev'
/tmp/cc0nN0eZ.o:(.rodata._ZTV15deletable_facetISt7codecvtIDsc10_mbstate_tEE[_ZTV15deletable_facetISt7codecvtIDsc10_mbstate_tEE]+0x10): undefined reference to `_ZNKSt7codecvtIDsc10_mbstate_tE6do_outERS0_PKDsS4_RS4_PcS6_RS6_'
/tmp/cc0nN0eZ.o:(.rodata._ZTV15deletable_facetISt7codecvtIDsc10_mbstate_tEE[_ZTV15deletable_facetISt7codecvtIDsc10_mbstate_tEE]+0x14): undefined reference to `_ZNKSt7codecvtIDsc10_mbstate_tE10do_unshiftERS0_PcS3_RS3_'
/tmp/cc0nN0eZ.o:(.rodata._ZTV15deletable_facetISt7codecvtIDsc10_mbstate_tEE[_ZTV15deletable_facetISt7codecvtIDsc10_mbstate_tEE]+0x18): undefined reference to `_ZNKSt7codecvtIDsc10_mbstate_tE5do_inERS0_PKcS4_RS4_PDsS6_RS6_'
/tmp/cc0nN0eZ.o:(.rodata._ZTV15deletable_facetISt7codecvtIDsc10_mbstate_tEE[_ZTV15deletable_facetISt7codecvtIDsc10_mbstate_tEE]+0x1c): undefined reference to `_ZNKSt7codecvtIDsc10_mbstate_tE11do_encodingEv'
/tmp/cc0nN0eZ.o:(.rodata._ZTV15deletable_facetISt7codecvtIDsc10_mbstate_tEE[_ZTV15deletable_facetISt7codecvtIDsc10_mbstate_tEE]+0x20): undefined reference to `_ZNKSt7codecvtIDsc10_mbstate_tE16do_always_noconvEv'
/tmp/cc0nN0eZ.o:(.rodata._ZTV15deletable_facetISt7codecvtIDsc10_mbstate_tEE[_ZTV15deletable_facetISt7codecvtIDsc10_mbstate_tEE]+0x24): undefined reference to `_ZNKSt7codecvtIDsc10_mbstate_tE9do_lengthERS0_PKcS4_j'
/tmp/cc0nN0eZ.o:(.rodata._ZTV15deletable_facetISt7codecvtIDsc10_mbstate_tEE[_ZTV15deletable_facetISt7codecvtIDsc10_mbstate_tEE]+0x28): undefined reference to `_ZNKSt7codecvtIDsc10_mbstate_tE13do_max_lengthEv'
/tmp/cc0nN0eZ.o:(.rodata._ZTI15deletable_facetISt7codecvtIDsc10_mbstate_tEE[_ZTI15deletable_facetISt7codecvtIDsc10_mbstate_tEE]+0x8): undefined reference to `_ZTISt7codecvtIDsc10_mbstate_tE'
collect2: error: ld returned 1 exit status
Compiling with newlib is impossible:
$ ppc-amigaos-g++ -athread=native test.cpp -o codecvt -lpthread -lstdc++ -lz
test.cpp: In function ‘int main()’:
test.cpp:28:10: error: ‘wifstream’ is not a member of ‘std’; did you mean ‘ifstream’?
28 | std::wifstream fin("text.txt");
| ^~~~~~~~~
| ifstream
test.cpp:31:5: error: ‘fin’ was not declared in this scope
31 | fin.imbue(std::locale("en_US.UTF-8"));
| ^~~
test.cpp:38:10: error: ‘wstring_convert’ is not a member of ‘std’
38 | std::wstring_convert<
| ^~~~~~~~~~~~~~~
test.cpp:39:70: error: expected primary-expression before ‘,’ token
39 | deletable_facet<std::codecvt<char16_t, char, std::mbstate_t>>, char16_t> conv16;
| ^
test.cpp:39:72: error: expected primary-expression before ‘char16_t’
39 | deletable_facet<std::codecvt<char16_t, char, std::mbstate_t>>, char16_t> conv16;
| ^~~~~~~~
test.cpp:40:28: error: ‘conv16’ was not declared in this scope
40 | std::u16string str16 = conv16.from_bytes(data);
@Sinan As i say in another topic, those mbstate and stuff undefs happens because you need to recompile stdc++ with new clib2. At least that what i were told by Andrea last time i asked about those undefs about mbstte. But i can't say 100% that this is the case, so you need to recompile stdc++ with new clib2 and try. If that will deal with - good, if not , then bug report to Andrea.
If i remember right, there were some script from Andrea which helps to recompile just stdc++ and not whole adtools.
What i mean, is that you need to recompile clib2's libstdc++ from adtools.
I.e. you do have your crosscompiler, and you build it with original clib2 coming with it (old one). Now, to have all works correctly in c++ code, you need to recompile adtools with new clib2 includes/libs/etc, so to have new clib2's libstc++ builded with new clib2 includes/libs.
In other words : libstdc++ coming with SDK are not enough, you need to recompile it with new clib2 includes/libs.
which changes the makefile to use the latest clib2 (head revision at the time of running make), among other things, like fix the broken issue of private Exec Reschedule function.
make -C native-build gcc-cross CROSS_PREFIX=/usr/local/amiga/
Just be sure that patches the same , i have it in /amiga/adtools, you may have it somewhere else. Also i install everything into /usr/local/amiga , you also may have some other paths.
Of course you also should have latest clib2 installed in SDK, so includes/etc will be taken from when recompilation happens.
After this all will be done, you can again try to recompile your test case (through i already tried - recompilation of libstdc++ indeed fix those linking issues).
c++ is different from c (library speaking) so you need to recompile libstdc++ with updated clib2 to avoid all problems. However I have an open issue that is causing some problems if streams are opened from c++ too early. It happens on shared libraries all of the times, while with static libraries it happened only one time in my tests. So you should be able to use c++ without any problem (after recompiling libstdc++ of course..)