Comments (10)
Sure, you just need to run :CocConfig and write the following line to your coc-settings.json file:
{
"clangd.fallbackFlags" : ["-xc++ -othercompilerflagsofyourchoice"]
}
For my use cases, setting fallbackFlags to the compiler flags I always use is sufficient. But adding the -xc++
flag to compile_flags.txt
works as well
from coc-clangd.
I figured it out by myself: Setting the language flag -xc++
explicitly sets the language for all files. Sorry for the spam
from coc-clangd.
Thanks, clangd interpreted .h as C++ in my machine, I solved it by adding -xc to compile_commands.json like this
[
{
"arguments": [
"-xc"
]
}
]
from coc-clangd.
I know this is old but it helped a lot.
For those searching latter it might be useful to add, you can add this same argument in a .clangd file at the root of the source files (if you have project specific configs there) or in the global config.yaml file.
CompileFlags: Add: [ -xc++, -std=c++20, ]
For me it was complaining about -std=c++20:
clang: Invalid argument '-std=c++20' not allowed with 'C' [drv_argument_not_allowed_with]
For me he was treating all .h files as C headers.
from coc-clangd.
can you please elaborate your solution?
Sure thing. In the root directory of your project, create a file called .clangd
if it does not already exist. In that file, add any compiler flags you want clangd to emulate inside the square brackets, separated by commas:
CompileFlags:
Add: [-xc]
(-xc is the one that fixed the issue for me)
Hope this works for you too!
from coc-clangd.
I had a similar problem. clangd thought the.h files in my C project were "Objective-C++" (didn't even know that was a thing). I would contend that that is a bug, maybe to do with how libc is set up on MacOS. I finally fixed it after finding this thread and adding -xc
to CompileFlags.
from coc-clangd.
can you please elaborate your solution?
Sure thing. In the root directory of your project, create a file called
.clangd
if it does not already exist. In that file, add any compiler flags you want clangd to emulate inside the square brackets, separated by commas:CompileFlags: Add: [-xc]
(-xc is the one that fixed the issue for me)
Hope this works for you too!
Thanks! I think I have figured it out that it can't be done(set C & C++ standard at the same time in clangd.fallbackFlags
) or it will cause the Invalid argument '-std=c99' not allowed with 'Objective-C++'clang
error.
But still thanks for letting me know the -x
flag in clang. Thanks!
For future readers:
from coc-clangd.
Hey, can you tell me how you solved this problem?
from coc-clangd.
Sure, you just need to run :CocConfig and write the following line to your coc-settings.json file:
{ "clangd.fallbackFlags" : ["-xc++ -othercompilerflagsofyourchoice"] }
For my use cases, setting fallbackFlags to the compiler flags I always use is sufficient. But adding the
-xc++
flag tocompile_flags.txt
works as well
thx!
from coc-clangd.
I had a similar problem. clangd thought the.h files in my C project were "Objective-C++" (didn't even know that was a thing). I would contend that that is a bug, maybe to do with how libc is set up on MacOS. I finally fixed it after finding this thread and adding
-xc
to CompileFlags.
I'm experiencing the same error in vscode-clangd, can you please elaborate your solution?
from coc-clangd.
Related Issues (20)
- Question: How to setup coc-clangd to format vector<vector<int> > instead of vector<vector<int>> HOT 2
- [coc.vim] server clangd failed to start: Error: spawn UNKNOWN HOT 7
- Intellisense issue with clangd coc.nvim extension HOT 18
- Refactoring Features HOT 2
- stdint.h Library error HOT 1
- Question: navigate to conflicting item/item causing error? HOT 4
- clangd don't start on windows HOT 1
- Unable to locate C/C++ header files (stdio.h, etc.) HOT 1
- coc-clangd still use c++03 to diagnose HOT 1
- some error flag but the code can running HOT 1
- How do I remove the automatically added parameter label in parentheses? HOT 1
- An issue of including libraries HOT 9
- Duplicate references HOT 2
- Command CocCommand clangd.install fails with error 'Failed to install clangd language server' HOT 5
- 这个插件如何在补全头文件比如#include<iostream>时,光标在>的右边,否则每次都多跳过这个符号一次 HOT 1
- [coc.nvim] Connection to server got closed. Server will not be restarted. HOT 4
- 'iostream' file not found (clang pp_file_not_found) HOT 1
- Connection to server got closed HOT 1
- coc-clangd没有输入头文件的情况下也能补全 HOT 4
- Header file not found, even though autocompletion works and include path is added correctly HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coc-clangd.