Giter Site home page Giter Site logo

Comments (10)

VukanJ avatar VukanJ commented on June 12, 2024 9

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.

VukanJ avatar VukanJ commented on June 12, 2024 8

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.

proc-moe avatar proc-moe commented on June 12, 2024 5

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.

Mikael-Pereira avatar Mikael-Pereira commented on June 12, 2024 3

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.

chvolow24 avatar chvolow24 commented on June 12, 2024 2

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.

chvolow24 avatar chvolow24 commented on June 12, 2024 1

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.

yaoyhu avatar yaoyhu commented on June 12, 2024 1

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:

  1. https://stackoverflow.com/a/78185524/17001641
  2. https://stackoverflow.com/a/19413311/17001641

from coc-clangd.

zhengweidi avatar zhengweidi commented on June 12, 2024

Hey, can you tell me how you solved this problem?

from coc-clangd.

zhengweidi avatar zhengweidi commented on June 12, 2024

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

thx!

from coc-clangd.

yaoyhu avatar yaoyhu commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.