Closed Season0518 closed 1 year ago
Can you build the program successfully with clang as the compiler, or only with gcc?
Could you please tell me what exactly it means? Is it compiled with g++/clang under the command line? Or run with CMake? On the command line, it can also be compiled normally. ScreenShot:
The screenshot shows compiling and running with the corresponding toolchain
Does clang++ main.cpp
work?
Yes,Because there is no bits/stdc++ header file under clang++, I replaced it with the header file that reported the error. The error persists, but compiles fine
Update: Both clangd and clang++ come from llvm
Can you try keeping <bits/stdc++.h>
but running clang with with clang++ -std=libstdc++ main.cpp
?
This is a closer approximation to how clangd is trying to parse the code.
I tried but it doesn't work
My bad, I made a mistake with the flag: I meant -stdlib=libstdc++
rather than -std=libstdc++
.
It doesn't matter, it's prompting like this now
Ok, I see, clang doesn't know about your libstdc++ installation. Clangd is able to find it due to the --query-driver
.
Let's try a different approach. Let's take the command that clangd prints in the log:
/opt/homebrew/Cellar/gcc/12.2.0/bin/aarch64-apple-darwin22-g++-12 --target=aarch64-apple-darwin22 --driver-mode=g++ -g -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk -o CMakeFiles/ACM_Env.dir/main.cpp.o -c -isystem /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/../../../../../../include/c++/12 -isystem /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/../../../../../../include/c++/12/aarch64-apple-darwin22 -isystem /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/../../../../../../include/c++/12/backward -isystem /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/include -isystem /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/include-fixed -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/System/Library/Frameworks -resource-dir=/opt/homebrew/Cellar/llvm/16.0.0/lib/clang/16 -- /Users/vm/test_cpp/main.cpp
and replace the compiler with clang++
as well as removing some of the stuff clangd adds that's not suitable for running on the command line to get:
clang++ --target=aarch64-apple-darwin22 -g -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk -o CMakeFiles/ACM_Env.dir/main.cpp.o -c -isystem /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/../../../../../../include/c++/12 -isystem /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/../../../../../../include/c++/12/aarch64-apple-darwin22 -isystem /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/../../../../../../include/c++/12/backward -isystem /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/include -isystem /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/include-fixed -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/System/Library/Frameworks -- /Users/vm/test_cpp/main.cpp
What happens if you run that?
Ok, I first executed it in the main.cpp directory, and he prompted an error,
and then I navigated to the build directory to find the .o file, and he prompted like this
Ok, so this indicates the issue is not specific to clangd, but rather clang itself doesn't support this type (__float128
).
Since clangd uses clang's parser, it's constrained to parsing code that clang can understand. In cases of projects normally compiled with gcc, this generally means making the code portable enough that clang can also compile it.
I'm not sure how to do that in this particular case, but as the question is now no longer clangd-specific (it's "how to get clang to accept this code"), hopefully you can find an answer to that elsewhere.
Ok, then I will disable this error in the configuration file of clangd using the “type_unsupported” option, sincerely thank you for your quick reply
Attaching my clangd config so others can solve this problem
Diagnostics:
Suppress: ["type_unsupported"]
Hello, I recently wrote some algorithm problems using Macbook on the M2Max chip. When I use the
bits/stdc++
header file, the header file displays:In included file: __float128 is not supported on this target
. But the program can be compiled normally. Is this a BUG or am I using it inappropriately?For a clearer description of the problem, here are my simplified directory structure and screenshots:
Error Info
Compile successfully
settings.json
compile_commands.json
CMakeFiles.txt
Logs
System information Clangd version (from the log, or
clangd --version
):Homebrew clangd version 16.0.0 Features: mac+xpc Platform: arm64-apple-darwin22.4.0
clangd extension version: v0.1.23
Operating system: MacOSX 13.3