I get a compilation error when trying to import <string>
and <iostream>
in the same file. Is there any known way around this?
This is what I have tried this far. (based on instructions from clang)
clang++-16 -std=c++20 -stdlib=libc++ -xc++-system-header --precompile "/usr/lib/llvm-16/include/c++/v1/iostream" -o "build/.mm3/default/iostream.pcm" -Wno-pragma-system-header-outside-header -Wno-user-defined-literals
clang++-16 -std=c++20 -stdlib=libc++ -xc++-system-header --precompile "/usr/lib/llvm-16/include/c++/v1/string" -o "build/.mm3/default/string.pcm" -Wno-pragma-system-header-outside-header -Wno-user-defined-literals
clang++-16 -std=c++20 -stdlib=libc++ "apa.cpp" -fmodule-file="build/.mm3/default/iostream.pcm" -fmodule-file="build/.mm3/default/string.pcm" -c -o "build/.mm3/default/apa.o"
// apa.cpp
import <iostream>;
import <string>;
int print() {
std::cout << "hello" << std::endl;
return 10;
}
The error message I get is
In module '/usr/lib/llvm-16/include/c++/v1/iostream':
/usr/lib/llvm-16/bin/../include/c++/v1/string_view:301:5: error: 'std::basic_string_view<char>::basic_string_view' from module '/usr/lib/llvm-16/include/c++/v1/iostream' is not present in definition of 'std::string_view' in module '/usr/lib/llvm-16/include/c++/v1/string'
basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT
^
/usr/lib/llvm-16/bin/../include/c++/v1/string_view:267:5
: note: definition has no member 'basic_string_view'
basic_string_view {
^
In module '/usr/lib/llvm-16/include/c++/v1/iostream':
/usr/lib/llvm-16/bin/../include/c++/v1/string_view:295:5: error: 'std::basic_string_view<char>::basic_string_view' from module '/usr/lib/llvm-16/include/c++/v1/iostream' is not present in definition of 'std::string_view' in module '/usr/lib/llvm-16/include/c++/v1/string'
basic_string_view(const basic_string_view&) _NOEXCEPT = default;
^
/usr/lib/llvm-16/bin/../include/c++/v1/string_view:267:5: note: definition has no member 'basic_string_view'
basic_string_view {
^
In module '/usr/lib/llvm-16/include/c++/v1/iostream':
/usr/lib/llvm-16/bin/../include/c++/v1/string_view:292:5: error: 'std::basic_string_view<char>::basic_string_view' from module '/usr/lib/llvm-16/include/c++/v1/iostream' is not present in definition of 'std::string_view' in module '/usr/lib/llvm-16/include/c++/v1/string'
basic_string_view() _NOEXCEPT : __data_ (nullptr), __size_(0) {}
^
/usr/lib/llvm-16/bin/../include/c++/v1/string_view:267:5: note: definition has no member 'basic_string_view'
basic_string_view {
^
In module '/usr/lib/llvm-16/include/c++/v1/iostream':
/usr/lib/llvm-16/bin/../include/c++/v1/string_view:312:37: error: 'std::basic_string_view<char>::basic_string_view' from module '/usr/lib/llvm-16/include/c++/v1/iostream' is not present in definition of 'std::string_view' in module '/usr/lib/llvm-16/include/c++/v1/string'
constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end)
^
/usr/lib/llvm-16/bin/../include/c++/v1/string_view:267:5: note: definition has no member 'basic_string_view'
basic_string_view {
^
In module '/usr/lib/llvm-16/include/c++/v1/iostream':
/usr/lib/llvm-16/bin/../include/c++/v1/string_view:339:5:
error: 'std::basic_string_view<char>::basic_string_view' from module '/usr/lib/llvm-16/include/c++/v1/iostream' is not present in definition of 'std::string_view' in module '/usr/lib/llvm-16/include/c++/v1/string'
basic_string_view(const _CharT* __s)
^
...
Edit: A temporary workaround seems to be to never import <string>
. <iostream>
seems to include std::string at the same time. So for now it seems like I will just change that, until the bug is fixed.
"Working" (compiling) example:
import <iostream>;
// import <string>;
int print() {
std::cout << "hello" << std::endl;
std::string str = "satnhoeu";
return 10;
}