I'm trying to play around with some new c++20 features but I am not able to compile even some simple lines of code.. I am working on macOS and first tried to compile it in Xcode with c++2a language dialect which didn't work out and then tried to compile the code from the command line with g++ but I got similar errors. Everything is up to date (Clang Vers 12, g++/gcc vers 10) and I know that there are still some issues with some features.
So here is an example:
import <iostream>;
#include <vector>
int main(){
std::vector<int> vec{1,2,3};
for (int e : vec) std::cout << e << std::endl;
}
compiled with:
g++ -std=c++2a -fmodules-ts test.cpp
Throws the following error:
header file <iostream> (aka '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream') cannot be imported because it is not known to be a header
So I assumed there is a problem with the header path from the toolchain which hasn't the latest updates so I tried changing the path to g++ main includes. So I tried:
g++ -std=c++2a -fmodules-ts -I/usr/local/Cellar/gcc/10.2.0_3/include/c++/10.2.0/ test.cpp
Which throwed this error:
test.cpp:1:8: error: header file <iostream> (aka '/usr/local/Cellar/gcc/10.2.0_3/include/c++/10.2.0/iostream') cannot be imported because it is not known to be a header unit
import <iostream>;
^
In file included from test.cpp:2:
In file included from /usr/local/Cellar/gcc/10.2.0_3/include/c++/10.2.0/vector:60:
/usr/local/Cellar/gcc/10.2.0_3/include/c++/10.2.0/bits/stl_algobase.h:59:10: fatal error: 'bits/c++config.h' file not found
#include <bits/c++config.h>
^~~~~~~~~~~~~~~~~~
2 errors generated.
Can someone help with this? I am aware that I can make this compile using #include - this was just as an example for working with new features - I had the same issue with eg import. I am really struggling with getting anything sorted - which compiler is the best usecase for c++20 and how and where can I include/locate the standardlib which has c++20 support? And how can I use everything together in Xcode?
gcc 10 does not support this yet. You can use gcc trunk or the gcc modules branch, and you need to add -fmodules-ts
to the command line.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.