Error code = 0x80070002 in visual studio c++ - c++

I just installed visual studio, (not new to coding) and I keep getting an error that goes like "error: unable to open file C:user...main.obj Error code = 0x80070002"
an Image of the error
this error shows up whenever there is something wrong with my code like for example if i do:
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
}
everything runs normal, but if I make a mistake say:
#include <iostream>
int main()
{
std::cout std::cout << "Hello World!\n";
}
I get the error, it's so annoying I don't want to get that error every time there is something wrong with my code the error list bar is enough, what do I do ?

Could you please tell us what version of Visual Studio are you using?
If you are using vs2017 or later, I suggest you could try to use /DEBUG:FULL property in "Linker/Debugging/Generate Debug Info.
I suggest you could refer to the Doc:
When you specify /DEBUG with no additional options, the linker
defaults to /DEBUG:FULL for command line and make file builds, for
release builds in the Visual Studio IDE, and for both debug and
release builds in Visual Studio 2015 and earlier versions. Beginning
in Visual Studio 2017, the build system in the IDE defaults to
/DEBUG:FASTLINK when you specify the /DEBUG option for debug builds.
Other defaults are unchanged to maintain backward compatibility.

Rebuild the program in a different disk or reinstall the VS could be the final solution I think.

Related

C++ Hello world keeps giving me errors in Visual Studio 2019

I'm just trying to print hello world using C++ but all I get is build errors. The error list shows 412 errors and they're mostly "Cannot open source file" followed by a file name that I haven't heard of.
It also says the WindowsSDKDir property is not defined and the solution I found was to repair visual studio when I looked up this problem. I completed repairing visual studio and I have the C++ selected in the workloads.
Even when I select "Console App" during initial set up it'll end up giving me the same errors even though that is supposed to set up a basic environment for Hello World.
My code is simply just to print out hello world.
#include <iostream>
void output();
int main()
{
output();
}
void output()
{
std::cout << "Hello World!" << std::endl;
}
So I just uninstalled Visual Studio completely and then reinstalled it. I realized I could have just modified it using the installer, but basically after selecting the C++ workload I made sure every box was selected on the right hand side. I don't know if I needed it all but I just installed everything to be sure and it finally worked.

LINK : fatal error LNK1181: cannot open input file 'opencv_world341d.lib'

I have found two similar questions this and this .
But they both use opencv, and opencv indeed provide the corresponding lib. I don't use opencv, and my project is very simple, just hello world.I have changed project default configuration like this
except for these configurations, others all take defaults
I just want to test my project configuration,that works find for win32 debug and release. But not work for x64 debug and release, they all tell me LINK : fatal error LNK1104: cannot open file 'opencv_world341d.lib'
I indeed know my project does not use any opencv lib, but why they tell me I need to use opencv_world341d.lib
my code
#include<iostream>
using namespace std;
int main()
{
cout << "hello world" << endl;
}
Thanks for everyone who comments on the question. I have solved the problem, although this problem not relevant to OpenCV to much, but I think the solution to the problem may be helpful to others. When I build project, visual studio 2019 tell me cannot link opencv_world341d.lib, so I go to Project->Properties->Linker->Input->Additional Dependencies , and I found opencv_world341d.lib. So I need to remove it, but it's readonly. From this we know visual studio using settings file (Microsoft.cpp..users.props) to control global settings including Global search path. These files are located at $(USERPROFILE)\appdata\local\microsoft\msbuild\v4.0 directory. Then I reedit Microsoft.cpp.<Platform>.users.props, delete opencv_world341d.lib, reboot visual studio, problem solved.

"CL.exe" Not Compiling C++ in stand alone project

How to fix "CL.exe" Not Compiling C++??
I have created a standalone python project on my desktop, keep in mind that I'm not using Visual Studio, I am in fact using pythontowin. I would like to compile a C++ file into a DLL to use for my python project. But I am getting weird unexplained errors when trying to compile with cl.exe.
Here is my C++ file.
#include <Windows.h>
#include <iostream>
using namespace std;
void Thread() {
cout < "Hello World" < endl;
Sleep(1000);
}
BOOL DllMain(HINSTANCE hDll,DWORD dwReason, LPVOID) {
if (dwReason == DLL_PROCESS_ATTACH) {
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Thread, 0, 0, 0);
}
return TRUE;
}
Command used for cl.exe: cl.exe /std:c++14 /LD ./../LibraryXdll.cpp
And this is the error I am getting: fatal error C1034: Windows.h: no include path set
If anyone could solve this error I would be very thankful and I can finish off my project thanks for the help. Regards RanOutOfQuestions!
Taking up on Tadman's comment:
It looks like you didn't set up your environment variables for use of cl.exe
If you have gotten cl.exe, you should also have a Bat-File called vcvarsall.bat or vcvars32.bat / vcvars64.bat. In case of a default Visual studio installation these can be found under "Program Files (x86)\Microsoft Visual Studio\version number\produkt type, e.g. community\VC\Auxiliary\Build".
Run the appropriate version of vcvars... (32 or 64 bit, or specifiy the flag for vcvarsall, see docs), and your include paths for THAT SESSION will be set (inside that terminal, if you close it the changes are lost again and you have to call vcvars again next time).
EDIT: Microsoft documentation on vcvars
You can work around that Reset by calling vcvars every time before executing the compiler, though this isn't a beautiful solution

What are the standard include paths for MS Visual C++?

I am trying to build a hello-world C++ application using Microsoft Visual C++.
#include <iostream>
int main() {
std::cout << "Hello, world. " << std::endl;
return 0;
}
I get this error:
main.cpp(1): fatal error C1083: Cannot open include file: 'iostream': No such file or directory
What are the standard include paths for Microsoft Visual C++?
Note: I am building from the command-line, not from Visual Studio
I actually just read through all of the documentation on this at: https://msdn.microsoft.com/en-us/library/ms235639.aspx
The material looks detailed and complete. If you get things configured like they require then it must work. They provide plenty of checks and conditions for ensuring that you are set up properly.
I am seriously suspecting that you aren't using a developer command prompt window.
I just did it myself and it works. Use Notepad and name the files like they tell you to do.
"Hello world!!"

Visual studio 2015 openmp support

I'm having trouble getting OpenMP support in Visual Studio 2015.
I've configured the project options to use /openmp (project->properties->C/C++->language->OpenMP support:yes), the code is as follows (very simple code, to test OpenMP):
#include <iostream>
#include <omp.h>
int main(int argc, char* argv[])
{
int n = 0;
#pragma omp parallel
{
std::cout << std::endl << "Hello World!";
}
return 0;
}
Only one thread runs and "Hello World!" is printed only once.
I was able to compile the program with VS2015 Community Version 14.0 Update 1 on Windows 8.1 64bit with OpenMP support.
Below, follow a list of steps that may help:
After create a new project and paste the source code, go to
Project-> Properties -> C/C++ -> Language
Change Open MP Support to Yes(/openmp)
Click Apply
On the left menu, go to Command Line and confirm that /openmp
appears somewhere at the compiler's options.
If it appears, click Ok and build the project.
Before run the program, put a breakpoint at the line:
int n = 0;
Run the the program by clicking on Local Windows Debugger
When the program stops at the breakpoint, go to Debug -> Windows -> Disassembly
Somewhere, near the breakpoint, look for an assembly line like:
call __vcomp_fork (?????????h)
If you find this line, chances are that openmp is ok and running.
Some other checks that can help:
Get a tool from Windows Sysinternals like Process Explorer (GUI) or ListDLLs (command line).
ListDLLs:
With the program stopped at the breakpoint, open task manager and look for the PID of the process.
Open a command prompt and run the command:
listdlls [PID] | findstr -i vcomp
Should appear something like VCOMP140D.DLL or VCOMP140.DLL or VCOMP????.DLL.
If it not appears, probably the compiler couldn't find the openmp dll so you'll have to see if this library is available at some point on your system.
Two last tips that may save your time:
If you change any configuration (e.g. Debug -> Release or x86 -> x64),
check again if Command Line has the /openmp option set ok.
If you try to force the compiler to C language (instead of C++), maybe the pragma:
#pragma omp parallel for
will not work (Update: Apparently this problem does not happen anymore on VS2017).
It shows me the message:
INTERNAL COMPILER ERROR in 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe'
Come back the compiler to C++ language and the parallel for will works ok.
Partial answer: I was not able to get the compiler to accept /openmp through the config/GUI, but compiling in console with cl.exe /openmp works.