Change vscode C++ library path - c++

Currently, I want to practice my C++ so I open a new folder to write some C++ codes. But weird thing happened. The editor shows me that one library bits/stdc++.h can not be resolved. Initially, I tried to delete and download MingW again at the D panel and reset the system path. But after that nothing changed.
I tracked the path of iostream (this one could be resolved) but found somehow my vscode point the library path at C->MicroSoft Visual Studio->2019....->iostream instead of D:/MingW/bin. I don't know how to solve this. So I tried running a cpp file at cmd that outputs "Hello World" to check my g++ setting, and it ran smoothly. I guess this is because my Vscode sets its library-finding path to the Microsoft VS 2019 but I can't find out where to change this.
Below will attach some screenshots as a detailed description, hope they can help you fix this question.
Note that I do not have the c_cpp_properties.json file, I also don't know why I don't have.
Now I want to set my editor library-finding path to D:/MingW/bin. Or if my assumption is wrong, please point out the correct way.

Change the header file to something wrong like "issotream". When it highlights it as an error, hover over it and select quick fix and click IncludePath. This will open a settings page, there you can add your bin path.

Open settings (UI if you're not comfortable with json), you can do it pressing
ctrl + shift + P
then select Preferences: Open Settings (UI) and search for include path. From the left drop down menu select Extensions -> C/C++ and navigate to Include Path. Here you can add new default paths.
Mind you that this will not tell the compiler anything about the libraries.

Related

VS Code unable to detect Standard C++ Libraries

I started using VS Code, and after messing around with it I kind of managed to make it detect Windows and Direct3D SDK's with the c_cpp_properties.json, but I'm failing to make the Standard Library work. So, if I do:
#include <string>
#include <vector>
It throws me an error just like this:
//Include file not found in include path
I've searched all over the web and didn't find any clue, so here I am! Strangely enough, if I just create a new .cpp file in an empty window/editor, it works. But the moment I 'load' the folder that file is in, then it fails. So, this is really driving me crazy.
I'm using Windows 10, with .NET 4.6.2, the 2015 Visual C++ Redist, and the Windows 10 SDK, all blazing new installs from today. My ultimate goal is to port a project I made in VS2013 to GNU/Linux, so I'm trying to make things work step by step.
Thanks a lot beforehand!
EDIT: Compiling with g++ works just fine, even though VS Code complains. This is what happens.
VS Code need to locate the include libraries.
First of all locate where g++ is located. You mentioned that it works fine. It's an .exe file (windows). So you may find g++ directory in path settings. view path variables.
Now after getting g++.exe directory you may easily find a file names string in nearby folders or parent folders. After successfully locating it copy its full path.
Now back in VS Code put cursor over green underline and you should see a bulb. Click it and in the options you will see option Edit "includePath" setting or Update "browse.path" setting. Select it and a file will open named c_cpp_properties.json
Now in that file locate "name": "win32". In the include path option paste the directory name of string file like this and you are good to go.
In vscode go to file>preferences>settings then select edit in settings.json (This can be hard to find, certain settings have this option by them, others do not. There is probably a better way to access this file, but I don't know it)
This will open up the settings.json file, where you can add the line:
"C_Cpp.default.includePath": ["C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\include"]
(or whatever your include path is) This will add that include path for all projects, or only the current workspace depending on if you open the settings.json file for "User Settings" or for "Workspace Settings"

VS 2010 Cannot open source file "string"

All of the sudden, the Intellisense in my VS 2010 project started going nuts.
Everything builds correctly, but it can no longer find basic C++ header files like string, map, etc. It no longer recognizes the std:: namespace, and it generally is just going haywire.
The code still compiles, but no matter what I do I can't get the Intellisense to work properly again.
The closest existing question I found was here:
VS 2010 error - cannot open file "iostream"
but that solution didn't work for me.
I have both 2012 and 2010 installed, so I'm wondering if one messed up the other. I'm using 2010 for this though.
Ok, I figured it out. It was related to this: VS 2010 error - cannot open file "iostream"; I just had to change it a bit.
1) Open the properties dialog. It wasn't clear to me what this actually meant in that answer. I was just right clicking on my project and selecting properties.
The correct thing to do is to select the individual sub-project underneath your solution.
With that selected, take your mouse to the top left of the solutions explorer. When you hover over that icon, you should see "Properties". Open that.
2) Open the directory properties. Select the VC++ Directories option under Configuration Properties.
3) Somehow for me, all these values had been cleared. To fix it, again closely related to the answer here: VS 2010 error - cannot open file "iostream", I did the following:
2a) For each of the directory values (e.g. Executable directories), select the drop down and click Edit...
2b) Deselect the Inherit from parent
2c) Click ok. You should see no change in the resulting Edit box.
2d) Click Edit... again.
2e) Click ok without changing anything.
2f) Now you should see e.g. $(ExecutablePath) for Executable Directories.
g) Repeat for each of the directory entries so at the end, Executable Directories will be set to $(ExecutablePath), Include Directories will be set to $(IncludePath), etc.
h) Finally click Apply and then Ok in the master dialog.
After doing this my Intellisense finally worked again.

Netbeans: cannot find include file <iostream>, also, unable to resolve identifier std, cout

I'm receiving the above errors on all my C++ projects on Netbeans. I also receive cannot find errors for anything else I try to include. Here's what it says when I hold control and hover over it: http://imgur.com/bBF2xuB. One of the projects actually builds and runs just fine, but all the rest fail either with "build failed, exit value 2" or the run fails with "run failed, exit value 127". I have absolutely no idea how to fix this and everything I've looked up to try to solve this hasn't helped. This wasn't a problem a few months ago when I was using Netbeans, and I'm not sure why the problem spontaneously popped up.
I just freshly installed Netbeans 8.0 and the latest cygwin version to try to fix this, but to no avail. I'm running Windows 7.
Please help, it would be greatly appreciated.
EDIT
The highlighted red errors in the attached photo are files/folders that do not actually exist. Could this be the problem, and if so, how can I go about fixing it?
EDIT 2
I deleted or changed some of the non-existent file/folder paths in the code assistance tab under the C/C++ tab under the options, this seems to have made some of the errors in the editor go away, but I still cannot build the project (and the errors haven't disappeared on this specific project), and the projects that I created in the past that used to work just fine are building, but I'm still receiving "RUN FAILED exit value 127".
I just had the same experience with Netbeans (8.0.2) not being able to find includes ("Cannot find include file") on Linux.
I had to do the following:
In the "Build Tools" tab under "C/C++" settings, click "Restore Defaults" to let it rescan for the tools, after which it picked up the paths to all the executables. Select the newly configured toolset as default and/or delete the old one to reduce confusion.
Under "Code Assistance", make sure the correct tool collection is selected, then click "Reset Settings" and "Apply". This populated all the necessary paths.
In my project settings, made sure I was using the right (newly discovered) tool collection.
After this, all the includes were picked up correctly and errors disappeared from the source checking.
I also had this problem (Cannot find include file iostream) in NetBeans IDE 8.1. I solved as follows:
Project properties -> Build -> C++ Compiler -> Basic Options -> C++ Standard -> C++98 or C++11 or C++14

NetBeans 7 c++ remote development host include path

Maybe this is a little bit esoteric, let's see how it goes.
I'm writing a c++ program using NetBeans 7 on a Windows 7 x64 box, but building on a remote development host, which is actually an Ubuntu Server 10.4 x64 virtual machine running on VirtualBox 4.
Source files are shared using VirtualBox shared folders. I've been able to create projects, build and debug them with no problems.
However, the code assist features of NetBeans keep on complaining that none of my include files can be found, and therefore I get a code assist "unable to resolve identifier" error for every single function call.
This is not very surprising, as the include files are actually in /usr/include, which is not part of the shared folder scheme, and therefore are not directly readable by NetBeans (it can and should read them using ssh though). But I would expect for NetBeans to allow me to set remote directories for code assist. I've looked through many settings and haven't found anything resembling what I'm looking for.
Sure, it's possible to just ignore this errors, but apart from me being near-OCD, that would be the same as disabling code assist, and I really appreciate it when the IDE tells me about a typo or other things that can be done with code assist.
Any ideas?
You might want to try the following settings in Netbeans, which solved my problem of code assist on remote hosts:
1) Project Build Settings
a - Right-click on the project in the project pane, select "Properties"
b - Expand "Build" and click "C++ Compiler"
c - In the "Include Directories", make sure you set the correct Configuration (Debug or Release) at the top, click the "..." to open the "Include Directories" window
d - Put the full path of the include directory. Notice that when you click "Select", Netbeans will automatically prepend the Windows path information. Since you are developing on a remote Linux host, you must now click the "Edit" button and edit this path to resemble the Linux file path (without the C:)
2) Netbeans Code Assistance Options
a - In the Netbeans menu bar, click "Tools" and then "Options"
b - Click "C/C++" at the top, then select the "Code Assistance" tab
c - Make sure the "Tool Collection" is set to the proper remote host at the top
d - For bot the "C Compiler" tab and the "C++ Compiler" tab, click "Add" and manually type the full path to the directory you want Code Assist to index.
e - Again, when you click "Select", Netbeans will automatically prepend the Windows path PLUS change the slashes to Windows slashes (ugh)... so now you must click "Edit" and edit those paths to represent the correct Linux syntax
Hope that helps!!

OpenCV - DLL missing, but it's not?

I am trying just a basic program with OpenCV with the following code:
#include "cv.h"
#include "highgui.h"
int main()
{
IplImage* newImg;
newImg = cvLoadImage("~/apple.bmp", 1);
cvNamedWindow("Window", 1);
cvShowImage("Window", newImg);
cvWaitKey(0);
cvDestroyWindow("Window");
cvReleaseImage(&newImg);
return 0;
}
When I run this, I get
The program can't start because
libcxcore200.dll is missing from your
computer. Try reinstalling the
program to fix this problem.
However, I can see this DLL. It exists. I have added the following to the input dependencies for my linker
C:\OpenCV2.0\lib\libcv200.dll.a
C:\OpenCV2.0\lib\libcvaux200.dll.a
C:\OpenCV2.0\lib\libcxcore200.dll.a
C:\OpenCV2.0\lib\libhighgui200.dll.a
What gives? I'm using visual studio 2008.
When I link the .dll files instead of .dll.a files, I get
fatal error LNK1107:invalid or corrupt
file: cannot read at 0x3F8
libcv200.dll
I followed instructions on http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2010 but was still stuck on exactly the same problem, so here's how I resolved it.
Fetched MSVC 2010 express edition.
Fetched Win 32 OpenCV 2.2 binaries and installed in default location.
Created new project.
Project setup
Project -> OpenCV_Helloworld Properties...Configuration Properties -> VC++ Directories
Include Directories... add: C:\OpenCV2.2\include\;
Library Directories... add: C:\OpenCV2.2\lib;C:\OpenCV2.2\bin;
Source Directories... add:
C:\OpenCV2.2\modules\calib3d\src;C:\OpenCV2.2\modules\contrib\src;C:\OpenCV2.2\modules\core\src;C:\OpenCV2.2\modules\features2d\src;C:\OpenCV2.2\modules\flann\src;C:\OpenCV2.2\modules\gpu\src;C:\OpenCV2.2\modules\gpu\src;C:\OpenCV2.2\modules\highgui\src;C:\OpenCV2.2\modules\imgproc\src;C:\OpenCV2.2\modules\legacy\src;C:\OpenCV2.2\modules\ml\src;C:\OpenCV2.2\modules\objdetect\src;C:\OpenCV2.2\modules\video\src;
Linker -> Input -> Additional Dependencies...
For Debug Builds... add:
opencv_calib3d220d.lib;opencv_contrib220d.lib;opencv_core220d.lib;opencv_features2d220d.lib;opencv_ffmpeg220d.lib;opencv_flann220d.lib;opencv_gpu220d.lib;opencv_highgui220d.lib;opencv_imgproc220d.lib;opencv_legacy220d.lib;opencv_ml220d.lib;opencv_objdetect220d.lib;opencv_video220d.lib;
At this point I thought I was done, but ran into the problem you described when running the exe in debug mode. The final step is obvious once you see it, select:
Linker -> General ... Set 'Use Library Dependency Inputs' to 'Yes'
Hope this helps.
Just add C:\OpenCV2.0\bin into your PATH environment variable
or
When you install OpenCV,
Choose the option, Add OpenCV to the system PATH for current user which is not default one
Just for your information,after add the "PATH",for my win7 i need to reboot it to get it work.
In Visual Studio 2013 you need to add this to the Environment Variables and then Restart your pc. This is the path where .dll file located in.
I have had numerous problems with opencv and only succeded after a gruesome 4-6 months. This is the last problem I have had, but all of the above didn't work. What worked for me was just copying and pasting the opencv_core2*.dll (and opencv_highgui2*.dll which it will ask for since you included this as well) into the release (or debug folder - I'm assuming. Haven't tested this) folder of your project, where your application file is.
Hope this helps!
You just need to add the folder of the needed dll file (or files) to your system "Environment Variables" in "Path".
Your problem will 100% be resolved. I had this problem too.
just open the bin folder and copy and paste the .dll files to the folder you are working in..it should fix the problem
As to #Marc's answer, I don't think VC uses the path from the OS. Did you add the path to VC's library paths. I usually add the DLLs to the project and copy if newer on the build and that works very well for me.
you can find the opencv_core248 and other dlls in opencv\build\x86\vc12\bin folder. Just copy the dlls you require into system32 folder. And your app should start working in a flash ! Hope it helps.
This might be like resurrecting a dead horse. But just so it's out there, the reason why the answer to these types of questions to simply put dll's into the system32 folder is because that folder is in the os's system path.
It's actually best practice to provide the os with a path link.
With windows 10
open up file explorer
right click on "this pc" and select "properties"
Now in the "Control Panel\System and Security\System" window that comes up, click on "Advanced System Settings" from the left hand panel.
At the bottom of the next window, click on the "Environment Variables" button.
On the next window, there are two panels, the top one is for modifying variables to the current user, and the bottom panel is for modifying variables to the system. On the bottom panel, find the variable "Path" and click it to select it, then click on the "edit" button.
Here you can then create, edit, delete, or update the different paths for the system. For example, to add mingw32-make to the system so you can access that command via command prompt, click new, then paste in the path to the bin. Example path, "D:\Qt\Tools\mingw730_64\bin", no quotation marks nor additional whitespaces.
Click ok on all the windows so that the changes are saved, then reboot your computer for the changes to be loaded.
The ".a" at the end of your DLL files is a problem, and those are there because you didn't use CMAKE to build OpenCV 2.0. Additionally you do not link to the DLL files, you link to the library files, and again, the reason you do not see the correct library files is because you didn't use CMAKE to build OpenCV 2.0. If you want to use OpenCV 2.0 you must build it for it to work correctly in Visual Studio. If you do not want to build it then I would suggest downgrading to OpenCV 1.1pre, it comes pre-built and is much more forgiving in Visual Studio.
Another option (and the one I would recommend) is to abandon OpenCV and go with EmguCV. I have been playing with OpenCV for about a year and things got much easier when I switched to EmguCV because EmguCV works with .NET, so you can use a language like C# that does not come with all the C++ baggage of pointers, header files, and memory allocation problem.
And as for the question of 64bit vs. 32bit, OpenCV does not officially support 64bit. To be on the safe side open your project properties and change the "Platform Target" under the "Build" tab from "Any CPU" to "X86". This should be done any time you do anything with OpenCV, even if you are using a wrapper like EmguCV.
Copy all .dll from /bin in System32
Just copy the .dll files to C:\windows\system32\
No need to do any of that. It is a visual studio error.
just go here:
http://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=31354
and download the appropriate fix for your computer's OS
close visual studio, run the fix and then restart VS
The code should run without any error.