Cpp extension with clangd

I tried using clangd 8 along with cpp extension. it works fine. But, I created a C file (not C++ file) with void main() method, clangd complains that return type of main() function should be int and not void.
I would like to be able to add & implement “void main()” method. How can i do it?
How can i add options to clangd to suppress certain warnings?

[original thread by rs]

[rs]

Also, this link describes installing clangd on ubuntu: https://github.com/theia-ide/theia/tree/master/packages/cpp. As theia docker image is based on node:10-alpine, it would be nice to get installation steps for node:10-alpine linux.

Hi @che-theia-new

You can use a preference to pass some startup parameters to clangd, permitting the disabling of categories of warnings. For the example above, the following should work:

“cpp.clangdArgs”: “-Wno-main-return-type”

We do not yet have a cpp docker image, but cpp is included in the “full” image (ubuntu-based): https://github.com/theia-ide/theia-apps/tree/master/theia-full-docker

[rs]

Thank you, @marc-dumais . Is the option “-Wno-main-return-type” an argument for clangd or a build option for clang compiler?

@che-theia-new It’s a @theia/cpp preference, that’s used as a startup parameter to clangd.

[rs]

Hi @marc-dumais , Thank you ! I tried the option “cpp.clangdArgs”: “-Wno-main-return-type”

[rs]

Here is the error that was logged:

[rs]

root ERROR C/C++: clangd.exe: Unknown command line argument ‘-Wno-main-return-type’. Try: ‘C:\Program Files\LLVM\bin\clangd.exe -help’ clangd.exe: Did you mean ‘-completion-style’?

@rs Confirmed - I get the same. I got fooled into thinking it worked because the diagnostics disappearing, but it did not work. As far as I can see, there is no way ATM to pass-on clang command-line arguments when starting clangd. Maybe asking the clangd community how to achieve this would be the way forward.

[rs]

@marc-dumais I tried adding “-Wno-main-return-type” to compile_flags.txt file added to project root folder, it seems to work. Could you please confirm?

@rs I confirm. The only little thing is that a frontend reload is required to pick-up the new or updated compile_flags.txt file. Maybe @theia/cpp should watch that file for changes and restart clangd when that happens.

Issue created: https://github.com/theia-ide/theia/issues/6104

[rs]

Thank you, @marc-dumais . Is there an option to turn off error that is shown for include files not found?

@rs can you provide code for an example of such an include error? Looking quickly I did not see a way to disable these errors, so the way forward might rather be to configure the project so that clangd can find these includes.

[rs]

specifying include file directories using -I option in compile-flags.txt solves the issue

[rs]

@marc-dumais & others, is there a way to specify preprocessor directives to clangd