@all
Am I doing something wrong while compiling following source with clib2 ?
#include <iostream>
#include <fstream>
#include <string>
#include <locale>
#include <iomanip>
#include <codecvt>
#include <cstdint>
// utility wrapper to adapt locale-bound facets for wstring/wbuffer convert
template<class Facet>
struct deletable_facet : Facet
{
template<class... Args>
deletable_facet(Args&&... args) : Facet(std::forward<Args>(args)...) {}
~deletable_facet() {}
};
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);