Visual Studio 2019 Debugger "Unable to start program ... Access is denied" caused by build file [duplicate] - c++

I have a solution in C:\full path here\VS2010\blender.sln
This solution contains many projects(around 100). When I compile them, they all work fine. I can run them without any problem, and (quite) everything works (there are some bugs).
One of the projects is ALL_BUILD, but it gives the same error if I try to debug INSTALL(another project). I'm compiling with RELWithDebInfo as configuration, and if I execute the program manually it works. It is outputted in C:\full path here\VS2010\bin\RelWithDebInfo
But if I try to run the compiler, it says
"Unable to start program
C:\full path here\VS2010\RelWithDebInfo\ALL_BUILD
Specified file cannot be found"
I tried to copy the compiled program into the path required by VS, but it raised the same error.
What should I do to solve this? Right now I set up cmake to generate also a mingw project and I compile it and debug it with gdb, but this is a really a slow and impractical workflow, and I would like to use the VS debugger.
I must say that if I compile with Debug as configuration, the program doesn't even start.
I'm using VS2010 Express on Win7 64bit
(This is a big open source program, so I don't know exactly whatever it does)

Guessing from the information I have, you're not actually compiling the program, but trying to run it. That is, ALL_BUILD is set as your startup project. (It should be in a bold font, unlike the other projects in your solution) If you then try to run/debug, you will get the error you describe, because there is simply nothing to run.
The project is most likely generated via CMAKE and included in your Visual Studio solution. Set any of the projects that do generate a .exe as the startup project (by right-clicking on the project and selecting "set as startup project") and you will most likely will be able to start those from within Visual Studio.

I had the same problem :)
Verify the "Source code" folder on the "Solution Explorer", if it doesn't contain any "source code" file then :
Right click on "Source code" > Add > Existing Item > Choose the file You want to build and run.
Good luck ;)

I think that what you have to check is:
if the target EXE is correctly configured in the project settings ("command", in the debugging tab). Since all individual projects run when you start debugging it's well possible that only the debugging target for the "ALL" solution is missing, check which project is currently active (you can also select the debugger target by changing the active project).
dependencies (DLLs) are also located at the target debugee directory or can be loaded (you can use the "depends.exe" tool for checking dependencies of an executable or DLL).

Related

Visual Studio Does Not Generate .exe File

I code an C++ program by VS 2022 but an error occurred when I tried to run it. I've built it successfully. I couldn't find any .exe file in 'debug' after I built it. It shows ('System can't find file'.)
There might be something wrong with your configuration.
You mention the build has been successful. In that case, the "output" window, when you choose "Show output from:", and there you have chosen "Build", that output should contain a line, containing the two characters ->. Those characters clearly show where your application has been built, like in this example:
App.Server -> C:\Whatever_Directory\App.Server.dll
Please check that directory. In case your compilation result is not there, it has been moved or deleted, most possibly by:
a post-Build build event: check your project's properties, "Build Events"
a virusscanner.
Good luck
The files can be complied outside of the project folder.
Right click your project > Open Folder in File Explorer > Navigate back one folder > x64 or x86 > Then you will see Debug or Release depending on what you have complied as.
Alternatively, the complier tells you the directory path where it has compiled to in the output window.

Linking to DLL via registry key ignored during debugging in Visual Studio

I'm working in VS 2019 on a C++ program in which I want to link into a bunch of 3rd party dlls, which are located in a folder separate from my executable. I don't want to copy all the dlls into the executable folder and have found the following solution.
Just like in the solution, I create a registry entry to define the keys with the information about the executable and the required path information to link to the DLLs:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MyExe.exe
%Path2MyExe%\MyExe.exe (default key)
Path = %Path2DLLs%
The compilation from within VS works fine and when I start the generated executables from outside VS by (a) double clicking or (b) by using the command line, the 3rd party DLLs are found and the program is executed as expected.
However, when I invoke the debugger from within Visual Studio (c), execution is halted right away complaining that DLLs cannot be found.
I have checked the present working directory from within the code using _getcwd and for all options (a-c) it indicates the same directory.
So the question is: why does option (c) - debugging from within VS - not work?!
Cheers, Sebastian
It's probably because the executable that's launched when debugging is a vshost executable, not the generated executable for the project, and so it needs a separate entry in the registry.
If you want to stick with this kind of a build (highly not recommended), the easiest way to debug is to disable the hosting process:
Following the suggestion by drescherjm I tried to prepend the DLL directory to the PATH variable in "Configuration Properties -> Debugging -> Environment" following this solution.
However, this did not work for me. I also added the path directly in the system environment dialogue without success.
What did work in the end is setting the working directory under "Configuration Properties -> Debugging -> Working Directory" to point to the DLL folder. Now all three calling routes (a-c) work as expected.
Thanks to everyone for taking the time to help me out on this.
Sebastian

Visual Studio build debug target .exe file-name mismatch

I am trying to build and run one demo in Visual Studio 2017.
But with compilation, the debug mode target gets the name with 'D' suffix instead of without it. (Specifically PDIconsoleD.exe instead of PDIconsole.exe) But when trying to run project already built project, it cannot find the file, because it looks for the name without this suffix (PDIconsole.exe).
I tried to run the file from the file browser, it got error, that I would like to debug.
Many thanks
PL.
Go to your project properties and check what is target name on different configurations. It might be that on debug mode it is changed to add suffig of 'D' so just delete that so it will be the same name for debug and release.

How do I inform the debugger of the location of run-time linked DLL files?

I have a C++ program that uses the freeglut library (and hence requires the freeglut.dll at run-time. I have added the folder C:\Program Files\Common Files\freeglut\bin to my PATH environment variable.
To confirm that the location is correct, when I compile my program (debug build) and run the resulting .exe file, it works fine (the freeglut.dll file is not in the same directory as the executable).
However, when I run the program directly from the VS2012 debugger, I get this message:
The program can't start because freeglut.dll is missing from your computer. Try reinstalling the program to fix this problem.
I know that one solution is to place the freeglut.dll file in the directory of the executable. This is what I've been doing so far, but I would much rather simply inform VS2012 (or my program) of where to find the dll file. Note that this post also seems loosely related, but it doesn't seem to contain an answer relevant to what I am trying to achieve (I just want the debugger to look in the same place for DLLs as any other program!).
How do I achieve this in VS2012? Icing on the question cake would be an explanation as to why the debugger doesn't just look in the PATH variable like any other program...
You can also set project based Environment:
Open project Properties
Go to Configuration Properites -> Debugging
Enter the path in Environment, eg:
PATH=$(PATH);C:\Program Files\Common Files\freeglut\bin
Restart Visual Studio after modifying your PATH variable.
What I did actually worked. I just didn't restart VS...

visual studio 2008 isn't creating an .exe file when i build my project. any ideas why?

i'm new to visual studio and couldn't find anything on google about this. i know this is an extremely noobish question, but i can't seem to find any info for it.
the debug shows me whatever i write, and the build has no errors, so i know the code i'm writing is fine.
the release folder doesn't contain the .exe, even after i build it, rebuild, clean, etc.
it's a win 32 console project. the release folder contains the .obj files, the manifest, the build log, idb, pch and pdb files (one of each)
Some possible reasons:
Did you accidentally create a class library project? In that case the output would be a DLL and not an EXE.
Does the output window or the error list display any build errors? In that case you should first fix these, then build again.
Did you change the configuration of the project, so that the output (EXE) is created in a different folder than the default one?
There's not a whole lot of reason for people to be guessing... You said you can find the build log - the exact location of any output file will be in there. To make sure you're seeing the right build log file, the output window in VS will have a link to the file that particular build run created:
1>Build log was saved at "file://c:\DevTrees\cppTest\Debug\BuildLog.htm"
1>cppTest - 0 error(s), 2 warning(s)
If you're having trouble interpreting it, post the contents.
I had the same problem; the advice above to look closely at the output window was just what I needed - thanks. My confusion was because I was looking in solution>project>Debug when VS put it in solution>Debug.
The Release and Debug folders contain outputs from different build configurations.
If you look in Project properties, you will see an Output Folder setting in the Build section, and it will be different for each configuration. (You can see the setting for each configuration using the dropdown list at the top of the Project Properties window)
The Release folder will only get populated when you build the project in the Release configuration.
To switch to the Release configuration, use the dropdown list in the toolbar.
EDIT: I am describing the UI for C# projects. It may be different for native code.
Are you sure that your project type is correct? A class library project won't build an executable. It would need to be some sort of application project to create an executable.
I had the same problem. The compilation went fine, but no .exe was generated in the target folder (.\Debug).
The problem was actually that the file containing the main() function was called "FooProject.cpp". I renamed it to "main.cpp" and then the .exe was generated properly.
In other IDEs such as Eclipse CDT, you don't need to have your main file called "main.cpp" as long as you have a proper main() function. This is apparently not the case for Visual C++.