Every now and then my VSCode IDE does not highlight errors in my C++ code anymore. Reloading the window, restarting VSCode or re-installing the extensions does not help.
Example:
void some_func() {
int some_num = 1;
some_nmn++; // should give error, since variablename contains typo. No error indicated.
}
In terms of C++, I am using the extensions only C/C++, however I also use a couple of other extensions that are helpful in the context, like CMake and Code Runner.
Apparently there were two things wrong with my setup: I had the wrong standard and I used the wrong Intellisense Engine.
Change the Intellisense Engine by doing Ctrl + Shift + P -> Preferences: Open Settings (UI) -> Enter C_Cpp: Intelli Sense Engine in the search bar. In the drop-down menu select Default.
After that I got a lot of unnecessary warnings regarding std, e.g. namespace std has no member optional (see post).
I fixed it by changing the standard in my workspace settings. Ctrl + Shift + P -> Open Workspace Settings (JSON). Add this line:
"C_Cpp.default.cppStandard": "c++17"
Be aware that the first setting is global and the second setting is only for your current workspace.
Something else must be wrong in your settings, or maybe some conflict.
Now as you uninstall VS Code it's possible that these settings are not erased, you can check the folders where the settings are kept and delete the them if necessary, the default locations for the settings are:
For Windows:
%APPDATA%\Code\User\settings.json
For macOS:
$HOME/Library/Application Support/Code/User/settings.json
For Linux:
$HOME/.config/Code/User/settings.json
Related
The behaviour i am looking for is when i type
using std::co then i expect it to autocomplete to cout (or at least suggest)
using std::vect then i expect it to autocomplete to vector
I have it set up on my laptop and it works perfectly fine ... it is just on my main vm that it does not. Sadly after a few hours of tinkering and googling not figured it out.
installed c++, build essentials, clang-format-3.8
vscode, c++ extention and c++ autocomplete.
noticed the one that worked had this added to the c_cpp_properties (not that i expected clang to help but was out of other options.)
,
"clang_format" : {
"style" : "file",
"fallback-style" : "LLVM",
"sort-includes" : false
}
I think it is probably a package difference but cannot see where that difference is. I also cannot find the difference in vscode config if there is one.
It also doesn't autocomplete for any included headers.
Infact i do not get autocompletion for using or include either.
In the one that doesnt work any autocompletion options i have shows the path into /usr/include/c++/5 wheras on the system where it does work i do not get any path info, only an abc icon and the command i want.
Edit: actually this does not fix std::<blah> autocomplete
Appears not to be working atm.
The fix:
File=>preferences->Workspace settings
then in user overrides this:
{
"C_Cpp.autocomplete": "Disabled"
}
if you scroll to bottom of the default settings you will see
// Controls auto completion for C/C++ code.
'Default' uses an experimental recursive directory tag parser (as of right now).
'Disabled' uses the word based completion provided by Visual Studio Code.
"C_Cpp.autocomplete": "Default"
Found this out when i saw this issue on github:
https://github.com/Microsoft/vscode-cpptools/issues/189
I simply want to include a C++ header file in KDevelop by writing
#include <file.h>
However, KDevelop automatically corrects the above statement to
# include <file.h>
I have not been able to figure out where I can change this. I want the first version, such that my files are similar to the other files in the project I am working on.
The file is type set correctly as a C++ file. I think the reason for the extra space is that KDevelop wants to indent the line because it is inside a conditional, i.e. a include guard as given below:
#ifndef THIS_FILE_H
#define THIS_FILE_H
// THIS_FILE_H
#endif
KDevelop also wants to indent the #define THIS_FILE_H line.
I have tried created my own indentation style by going to the Settings -> Customize KDevelop menu item, and then clicking on Source Formatter on the left. When defining the formatting style, I have disabled the indentation of preprocessor directives, nevertheless, it has no effect on the indentation of the #include and #define inside the include guard.
I know this is quite old but here is my advice, for future reference.
Go to Settings -> Configure KDevelop -> Code Formatter.
There you'll be able to see a dropdown the language you want KDevelop to format (C, C++, C#, Java, and whatever), the formatter ("Artistic Style" or "Custom Script Formatter") and a list of possible predefined styles plus buttons to customise your own.
Check whether you have selected one suitable predefined and try a few ones to see what happens.
KDevelop should stop adding the extra space after # include after this.
Question: does your KDevelop also adds a space after a #define as well?
Same Problem. So, I uninstall kate, then remove all config files in home directory whose name contains kate. Then I opened kdevelop and found nothing change. At last, Kdevelop->Settings->Open/Save->Modes&Filetypes, select Sources/C++ and Sources/C, change it to None, restart kdevelop. OMG, finally, the world is peace.
To conclude, the Sources Modes&Filetypes occur the problem.
The automatic spaces appear to be caused by the indentation mode, which (in KDevelop 4.7.1) you can switch for the current file via Editor -> Tools -> Indentation. If indentation is set to C++/boost Style, you'll get those weird automatic spaces while typing; while in mode Normal you only get the usual indentation at beginning of line.
The default indentation mode can be set in Settings -> Configure Editor -> Open/Save -> Modes & Filetypes. For each Filetype (eg. Sources/C, Sources/C++, Sources/C++11, Sources/C++11/Qt4) the Indentation Mode can be set independently.
KDevelop appears to remember the setting for files you have opened once; so for these files the new configuration settings have no effect. I don't know how to make KDevelop forget these per-file settings.
I have checked all fields in Eclipse/Preferences/Editor/Content Assist/Advanced but I still can't view any default proposal while executing Ctrl+Space, even if my code recognizes if statements or include's(I have installed C/C++ Development Tools).
For instance I would like to be able to view all proposals while typing
"lastTrackableId = trackable(Ctrl+Space)" instead of getId(); in the above code
lastTrackableId = trackable.getId();
Any help please?
go to Window/Preferences/C/C++/Editor/Content Assist/Advanced -> select the needed proposals.
if it still doesnt work, check another type of eclipse. (Actually, I have Eclipse IDE for Java EE Developers, and I imported the needed files)
other option: go to Window/Preferences/C/C++/Editor/Content Assist/ and Restore Defaults and restart eclipse.
I'm trying to set my project include to the path %OPENCV_246%\..\..\include
This resolves to the path F:\dev\opencv_246\build\include
However, when setting the project includes, that path will not resolve and as a result the included headers break.
I've tried both %OPENCV_246%\..\..\include and $(OPENCV_246)\..\..\include with no luck.
Using the path directly fixes my includes, but I'd like to have a better way of managing the path through environment variables.
In the screenshot I've added both for clarity, If anyone could point out the step I'm missing here I'd appreciate it.
EDIT: Variable OPENCV_246 contains value F:\dev\opencv_246\build\x86\vc11
Dev studio won't recognize any environment variables that have been changed since it was started, so if you change one, a restart is required (of Dev studio, not the computer).
https://superuser.com/questions/107521/why-are-changes-to-my-path-not-being-recognised
This sounded similar to my problem, which was getting VS2013 to acknowledge a change I made to my environment variable (in my case QTDIR). Even after a restart and a shutdown, it obstinately hung on to the old value !! (you can see the value if you go to edit a project setting, hit the "Macros" button, and scroll down the list to find e.g. "$(QTDIR)" )
Here it suggest VS2010 cahed values heavily, but 2013 seems even more keen !
After some FindInFiles for the old path, it seems that VS2013 caches environment variables in your .vcxproj.user file. I have no idea how it got in there in the first place.
So I deleted the entry, closed the solution, checked the file again in WordPad to make sure the entry hadn't been put back in. Then I re-opened the solution, but the old value was still there in the Macros list !
Closing VS seems to have done the trick. Now it seems to have the right path - although I'm sure I checked after I first opened the solution and QTDIR wasn't in the Macros list at all - maybe I'm confused...
Well, it all seems to be working now, and my project builds and links to my Qt libs without complaints :-)
And, the entry in the vcxproj.user file hasn't come back. So I still don't know how it got in there. Maybe I did something to cause it a while back in a previous version of VS...
I have combined several projects into one solution. I created empty solution and added these projects and here is a blue print of how it looks like:
Root:
Project1 - directory
Project2 - directory
Debug - directory
Main.sln - file
Now I want to direct the executable and dll from both projects to \debug folder shown up of the solution file. I go into project properites >> Configuration Properities >> General >> 'Output Directory' and change the output directory to $(SolutionDir)$(Configuration)\ which is default for a new project.
The problem is that it has no effect on where the output file is created, it is still created in the old destination. The old path for `Output Directory' was .\Debug\ not that it matters.
Could this be because the SolutionDir & Configuration may not be defined? Where can I see their definition or values? I also want to create a new configuration which would be 'Release with Debug' how can I create that using environment variable? Thanks!
My project is MFC/Visual C++.
Add-on:
Where are these identifiers like SolutionDir defined in the scrip? I look up for in .vcxproj file but there is mention of it. I create a new dummy VS2010 project just to look at it's .vcxproj file but these project settings identified are not defined in any place that I can see!
This is most likely caused by specific settings overriding global settings, namely Linker's "output" setting. This happens often as a result of conversion from earlier Visual Studio.
What you need is to go through every setting, paying attention to those whose values are written in bold, and reset to default (select it from dropdown) every setting with 'debug' or 'release', and others as necessary.
There could also be specific settings on files. I usually resolve this by opening project in notepad and removing any excessive settings. Just be careful. Using multiline replace in Notepad++ or any other capable editor helps.
I think I had a similar problem.
What I ended up doing was editing the vcxproj file directly. Find this section and edit it like this for each of your configurations:
<PropertyGroup>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
</PropertyGroup>
I had a similar problem with the Intermediate Directory setting in one of my VS2010 projects. No matter what I set it to, it would always use the default value of $(SolutionDir)$Configuration. Oddly, other projects in the same solution with the same settings worked just fine.
After playing around, I stumbled upon a solution.
Click on the setting in the propery page dialog.
Click on the down arrow button in the right-hand side of the edit box.
Select "inherit from parent or project defaults".
Click "Apply".
Click on the setting and change it to your desired value.
I don't know why this works, but it does. It seems like the macros were not being properly evaluated for whatever reason. Then, after you apply the inherited values, it seems to reset itself and start evaluating the macros properly.