Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make CLion to recognize .c files as c++ (and not as plain c)

Tags:

c++

c

ide

clion

By default CLion C and C++ files has united file type in Settings->Editor->File Types But in inspect code .c file recognize as plain C (for example type bool requires the inclusion < stdbool.h >) but actually it must be compiled as C++

Help->About: CLion CL-140.2310.6 Build #CL-140.2310, built on February 12, 2015 ...

like image 647
Alexey Nikitin Avatar asked Oct 15 '25 08:10

Alexey Nikitin


1 Answers

for CMakeLists.txt project (without clangd completion)

Put

SET_SOURCE_FILES_PROPERTIES(${SOURCE_FILES} PROPERTIES LANGUAGE CXX)

in your CMakeLists.txt.

  • https://intellij-support.jetbrains.com/hc/en-us/community/posts/205822539/comments/205713325
  • https://cmake.org/cmake/help/latest/command/set_source_files_properties.html
  • https://cmake.org/cmake/help/latest/prop_sf/LANGUAGE.html

As commented by user7610 below this seems not to work when clangd completion is enabled (though I haven't confirmed it yet).

for compilation database project

insert ""-xc++"," to [].arguments[1] in compile_commands.json.

--- compile_commands_original.json  2022-03-10 12:08:05.025572787 +0900
+++ compile_commands.json   2022-03-10 12:09:16.250045217 +0900
@@ -12663,6 +12663,7 @@
     {
         "arguments": [
             "g++",
+            "-xc++",
             "-c",
             "-std=c++11",
             "-fno-PIE",

(This happens when I build gcc with bear.)

like image 136
wataash Avatar answered Oct 16 '25 21:10

wataash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!