I finally set up the VSCode environment, just 1 remaining problem with #include as on the following image:
I checked many google results with similar, but not the same problem. The thing is that it compiles and runs correctly, even the intellisense suggests me the iostream file, but when I add it into the #include, error:
'iostream' file not found
appears.
What is wrong and how to fix it?
open your c_cpp_properties file in the project, add as follow configurations.i use of the clang.
"c-cpp-flylint.clang.includePaths": [
"${workspaceRoot}",
".",
"C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++",
"C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++/x86_64-w64-mingw32",
"C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++/backward",
"C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include",
"C:/llvm/include",
"C:/llvm/x86_64-w64-mingw32/include",
"C:/llvm/lib/gcc/x86_64-w64-mingw32/7.1.0/include-fixed",
"C:/LLVM/lib/gcc/x86_64-w64-mingw32/7.1.0/include/ssp"
]
pay attention to these path. they include necessary files when you complie,of course ,it is useful for me because of according to my files in the pc.you can custom to configure them. i hope my answer to help you out.if have any question,it is free to contect to me.
find the "setting".("file"——》"first choice"——》setting)(or click "ctrl"+",")..then search "clang.diagnostic.enable", then undo the "Enable diagnostic"
Related
I feel like this should be basic, but I can't find anything for it online. I downloaded OpenCV and can't figure out how to have my projects recognize it. When I try to include it with like
#include <opencv2/core/version.hpp>
I get the error:
"No such file or directory"
The only solution I've tried is to add /usr/include/opencv4/ to my PATH. Also, I am running ArchLinux if that is helpful to know.
So I ended up just moving the directory /usr/include/opencv4/opencv2 to /usr/include and that worked. Unless there are any ways to add directories to the list of directories that c++ checks when running the #include, this is the only way I've figured to solve it.
if you have trouble with this
#include <opencv2/core/version.hpp>
You can find more detail information on "Googling".
what I have organized shown below:
try using include "opencv2/core/version.hpp" instead of it.
right-click, then check-the-location
recheck several environment settings:
Additional Include Directories
Linker
Additional Dependencies
PATH
Try changing these three:
PATH=$PATH:/usr/bin
CPATH=$CPATH:/usr/include/opencv4
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64:/usr/lib
I am coding a project in C++ in CodeBlocks, and I am trying to use the hashlib++ library, and I have it in my code as such:
#include <hashlibpp.h>
When I click "build and run", on that line of code I get the following error:
fatal error: hashlibpp.h: No such file or directory
I have the entire hashlib++ library in the same directory as my main.cpp file.
I was following the instructions on the documentation at http://hashlib2plus.sourceforge.net/doc/README.TXT.html
but either the instructions in sections 3.1 and 3.2 did not work or I did not follow them properly.
I would appreciate any insight as to why I am getting this error.
Ok, so I figured out what the issue was. By section 3.1,
Go to your project in the "Management" tab, and right-click the project you are working on. If you cannot see that section go to View > Manager, or press Shift + F2.
After right-clicking, select "add files..." and simply find and add the .h file you will be using. After it should show up in the "Management" section in a folder called "Headers".
Type in appropriate #include line in your code. I downloaded the entire hashlib2plus folder and put it in my project folder, so mine looked like
#include "hashlib2plus/trunk/src/hashlibpp.h"
Hope this resolves any issues in the future!
I am using Visual Studio Code in my C++ project. I installed Microsoft C/C++ Extension for VS Code. I got the following error:
#include errors detected. Please update your includePath. IntelliSense features for this translation unit (/path/to/project/file.cpp) will be provided by the Tag Parser.
Close and re-open Visual Studio Code.
The answer is here: How to use C/Cpp extension and add includepath to configurations.
Click the light bulb and then edit the JSON file which is opened. Choose the right block corresponding to your platform (there are Mac, Linux, Win32 – ms-vscode.cpptools version: 3). Update paths in includePath (matters if you compile with VS Code) or browse.paths (matters if you navigate with VS Code) or both.
Thanks to #Francesco Borzì, I will append his answer here:
You have to Left 🖰 click on the bulb next to the squiggled code line.
If a #include file or one of its dependencies cannot be found, you can also click on the red squiggles under the include statements to view suggestions for how to update your configuration.
If you are working with cmake-tools and the error messages says something is wrong with the configurationProvider, then you have 2 options:
Use ms-vscode.cpptools instead of ms-vscode.cmake-tools
Define the headers in CMakeLists.txt
Option 1: Use ms-vscode.cpptools instead of ms-vscode.cmake-tools.
Open c_cpp_properties.json. (windows key on windows or cmd key on mac + shift + p, enter "c/c++ edit configurations" and chose 'json'.
Enter ms-vscode.cpptools as value for configurationProvider instead of ms-vscode.cmake-tools or whatever you have.
How it should look like after the replacement of configurationProvider:
One other important configuration is the include path. The assumption is that you have this configuration right. May be like following
Option 2: Define the headers in CMakeLists.txt
When configurationProvider is set to ms-vscode.cmake-tools in c_cpp_properties.json, VS Code uses the include information defined in the CMakeLists.txt instead of reading the includePath configs in VS Code.
So you need to setup the include path correctly:
using the include_directories command (rather than the target_include_directories command) to define the headers
Configure the project to reflect the change happened in the previous step.
Left mouse click on the bulb of error line
Click Edit Include path
Then this window popup
Just set Compiler path
I ended up here after struggling for a while, but actually what I was missing was just:
If a #include file or one of its dependencies cannot be found, you can also click on the red squiggles under the include statements to view suggestions for how to update your configuration.
source: https://code.visualstudio.com/docs/languages/cpp#_intellisense
The error message "Please update your includePath" does not necessarily mean there is actually a problem with the includePath. The problem may be that VSCode is using the wrong compiler or wrong IntelliSense mode. I have written instructions in this answer on how to troubleshoot and align your VSCode C++ configuration with your compiler and project.
I'm on a Macbook M1 Pro, and I had red squiggly error lines all over my C++ files. To solve, I did this:
Open Preferences -> Settings
Search for intelliSenseEngine
Change "C_Cpp: Intelli Sense Engine" from Default to Tag Parser
alternatively, you could create a .vscode folder in your project root, and then create a settings.json with the content of
{
"C_Cpp.intelliSenseEngine" : "Tag Parser"
}
ideally, you should have a c_cpp_properties.json file in the same folder with the right settings as well.
Note: I got this idea from Github here.
I was trying a hello world program, and this line:
#include <stdio.h>
was underlined green. I tried:
Deleting the line
Re-writing the line
Clicking the yellow bulb and choosing to update
fixed the error warning. i don't know if it fixed the actual problem. But then i'm compiling via a linux VM on Windows 10
Go to your c_cpp_properties.json file by searching from settings.There you might see the following code
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
Change the compiler path as below
"compilerPath": "/usr/bin/g++",
After closing and reopening VS, this should resolve.
For Windows:
1.Install Mingw-w64
2.Then Edit environment variables for your account "C:\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin"
3.Reload
For MAC
1.Open search ,command + shift +P, and run this code “c/c++ edit configurations (ui)”
2.open file c_cpp_properties.json and update the includePath from "${workspaceFolder}/**" to "${workspaceFolder}/inc"
If someone have this problem, maybe you just have to install build-essential.
apt install build-essential
For me, using Ubuntu, I just had to install gcc to solve this issue.
sudo apt install gcc
Then, set the compiler path to gcc. Go to your c_cpp_properties.json file, set:
"compilerPath": "/usr/bin/gcc"
An alternative answer would be opening VS Code in remote WSL, if you going to compile files with g++. Just close your VS Code and open WSL and type code . After that the File Explorer shows that VS Code is now running in the context of WSL with the title bar [WSL: Ubuntu]. But make sure you'd installed the GNU compiler tools and the GDB debugger on WSL.
source: https://code.visualstudio.com/docs/cpp/config-wsl
In my case I did not need to close the whole VS-Code, closing the opened file (and sometimes even saving it) solved the issue.
I had luck removing the comments from c_cpp_properties.json in the .vscode folder. Comments aren't permitted in json files by default and you can't simply rename it .jsonc. Referenced In VS Code, disable error "Comments are not permitted in JSON"
My header file was in include/head.h, code in src/code.cpp. I wrote
#include "head.h"
and got this error. Changing it to
#include "../include/head.h"
fixed it.
I solved this problem, once I removed configurationProvider node and set
cStandard and cppStandard to default values:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}",
"${workspaceFolder}/**",
"${workspaceFolder}/test",
"/opt/qt5/include/QtCore",
"${workspaceFolder}/test"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}
after you install the c/c++ extension, two files are created inside .vscode folder.
open c_cpp_properties.json file and paste this key-value pair inside configuration object.(if it doesn't already exists)
"configurationProvider": "ms-vscode-cpptools"
if it does already exists in the object, see if the value part is ms-vscode-cmaketools. if such it is, replace that existing line with above line.
this will allow you to execute your cpp files along with c files.
I solved the error on my Mac by just clicking on the Edit "include path settings" and changing the compiler path to /usr/bin/clang.
For Windows:
Please add this directory to your environment variable(Path):
C:\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin\
For Include errors detected, mention the path of your include folder into
"includePath": [
"C:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/include/" ]
, as this is the path from where the compiler fetches the library to be included in your program.
In case you've copied and pasted code into your new file in VS Code
Please delete #include <iostream> and try to build again.
I am having trouble getting Xcode to find opencv header files. In the 'Build Settings' tab I added the recursive path '/usr/local/Cellar/opencv3/include' to 'Header Search Paths' and 'User Header Search Paths' and I have an include of #include "opencv2/core.hpp"
I added the path to both keys because it wasn't working for either one individually so that's just the way I have it right now. The error I get is 'opencv2/core.hpp' file not found. Any suggestions? I'm pretty sure this should be working.
EDIT 1: I also have the key 'Always Search User Paths' set to 'Yes'
My apologies to those who spent time trying to figure out what was wrong. The problem was that I had set the build settings for the UI tests target rather than the application project.
In case others come across the same mistake, This is where the target can be changed:
I don't remember ever changing it in the first place, but apparently I did at some point.
Hopefully this is helpful to the next guy that makes this simple mistake.
I was trying to #include a cpp file with some functions so I can use that cpp file later with other projects. It gave me an 'already defined in .obj' error and since then that .cpp file was like binded with my project. (I understood that's not the way, the answer here helped me with the already defined)
If I exclude the .cpp file from the project, remove it from the directory and remove the #include line it still looks for it:
c1xx : fatal error C1083: Cannot open source file: 'std.cpp': No such file or directory
Diagnostic:
Outputs for D:\MY DOCUMENTS\C#\PROJECT\D3DTESTC++\COWS AND BULLS\CBMAIN.CPP|D:\MY DOCUMENTS\C#\PROJECT\D3DTESTC++\COWS AND BULLS\STD.CPP: (TaskId:15)
It shouldn't be looking for the std.cpp at all, I removed it! So is there a way I can reset the project and recompile so that the program doesn't look for it? I already tried Rebuild and Clear -> Build Project
When I ran across a similar problem with VS Express, I wound up having to open up the the .vcxproj file (which is just XML), and remove the offending
< ClInclude Include="FILEPATHANDNAME" > tags.
Many of the solutions here will not work
Fullproof method:
Open the vxproj file that is giving you trouble in a text editor.
remove all references to the file it cannot find.
OK, I have no idea how I did it but I'm still going to try to write what I did.
Save all and Close solution
Open the .vcxproj file (not .sln)
Build -> Clean [Project Name]
Save all and Close
Open the .sln file again.
Build -> Project Only -> Clean Only [Project Name]
Build -> Project Only -> Build Only [Project Name]
That's exactly what I did and worked for me. I think the main thing to do is clean, save, close, open, build, but I'm not sure.
In Solution Explorer you can select/deselect option "Show All Files".
Try both options and make sure excluded file is not included in project for both of them.
That's what I had:
I used "Show All Files" option (so you can see all the files in project directories). I excluded one of my .cpp files from project. However, it behaved as this file is in project.
That's how I managed to fix it:
I switched "Show All Files" off and saw this file still belongs to project! So I excluded this file once again.
As I see, that's a known issue.
This worked for me, hope it will be useful for someone else.
Try to verbose builder output to see exact steps of what's going on. I suppose, you use Visual Studio, right?
Go to menu "Tools -> Options"
In options dialog, select "Projects and Solutions -> Build and Run"
Change current mode of "MSBuild project build output verbosity" from "Minimal" to something like "Diagnostics" or "Detailed".
Rebuild your project and investigate Output windows
Builder dump should shed more light on your current settings (I suspect you have more references to that file than you expect)
This happened to me because I renamed folder from inside the IDE. None of the above solutions worked. The only way to fix this is by opening vcproj in notepad and you should see the offending files in the <ItemGroup>. Just delete those lines.
Or sometimes, like in my case, the issue is simply in the naming of the folders in the location. I had a very long path with folders that I like to name with special characters so they show up at the top and it's easy to access them.
As soon as I put my solution in a folder just in D: drive, the issue was gone.
When I renamed a file, I found I had to go to SolutionExplorer, Source File, select the file, first exclude from Project, then re-add it to project, and rebuild the solution it lives in. It was still showing up as the old file name under Source Files for me.
I had the same problem, but I had another .sln worked fine. After tooling around with the Project->Properties-> to make them look identical, nothing worked. I opened both .vcxproj files and copied the contents of the working version into my non-working version. (I noticed that the two files had different lengths. The non-working version was longer by about 20 lines.) I just changed the RootNameSpace to the non-working version's name. I saved the non-working file and presto! It worked.
I removed those sources from Project and re-added them. Somehow, references were messed up after a hurry project refactoring.
For people having problem related to "error C1083: Cannot open source file":
Error is caused by settings in *.vcxproj file. Probably you deleted/moved source file by file explorer, not by Visual Studio's "Solution Explorer". Thus, your *.vcxproj file is corrupted. Fix is to manually correct settings in *.vcxproj file.
How Visual Studio settings files work
Visual Studio saves solution's info into file. This file is usually in project's solution directory, has extension .sln and base name is same as name of solution, f.ex.:
NameOfSolution.sln
Similarly, project's info is saved into one file (each project has its own file). Base name of this file is name of project, extension is .vcxproj, and usually is located in subdirectory named as your project, f.ex.:
NameOf1stProject/NameOf1stProject.vcxproj
NameOf2ndProject/NameOf2ndProject.vcxproj
Both *.sln and *.vcxproj files are textual files. You can open them by using Notepad.
How to fix problem
Find *.vcxproj file responsible for your project.
If you don't know where it is, open in Notepad the *.sln file of your solution. Search for name of your solution. You will find line like:
Project("{9AA9CEB8-8B4A-11D0-8D22-00B0C01AA943}") = "NameOf1stProject", "NameOf1stProject\NameOf1stProject.vcxproj", "{A8735D0A-25ED-4285-AB8F-AF578D8DB960}"
Value under "NameOf1stProject\NameOf1stProject.vcxproj" is location of *.vcxproj file of your project.
Open found *.vcxproj file by text editor (f.ex. Notepad).
Search for line on which is filename you are struggling with.
Example: if you are looking for "RemovedFile.cpp", then you should find line:
<ClCompile Include="RemovedFile.cpp" />
Delete that line.
If you have opened Visual Studio, it asks you if it should refresh solution - select yes. If it is not opened - just start using it.
In case of any problems, try to rebuild solution (top banner -> Build -> Rebuild Solution)
In my cases, it worked. 30 mins of trying to fix, <1 minute of fixing.
This helped in my case. To sum it up, my path to the project was too long, so I moved my project to something shorter i.e. D:\my_project and everything worked in a blink of an eye.
I had this same problem, but for me the issues was that I was using Bash on Windows (WSL) to clone the repository and then using VS to compile.
Once I deleted my clone and used Windows command line (cmd.exe) to clone the repo then the error 1083 went away.
This is caused by not removing/deleting the file properly. Go to Solution Explorer, select your solution, at the left corner, activate the icon: show all files.
(if you already removed the problem file, restore it from recycle bin)
Select the problem file, do remove and delete from within Solution Explorer and you should not have this problem. And remember to do it the proper way from now on.
This is on MS 2010
If you have that file in your project directory but you still got the error, on your IDE go to Solution explorer--> Remove that file-->then open the project directory on your file explorer-->Select that file and drop it on a specific location in IDE solution explorer. I fixed it this way. I use the Windows platform.
I got this error when I got a code from my peer and I tried directly running it on my system. Ideally to avoid such errors, I should have just copied the source and header files and should have created the VS solution of my own.
To resolve the errors I removed the files from the Solution Explorer and added them again. Following image shows the Solution Explorer window.
The remove option comes after right clicking on the file names.