How to change the working directory in visual studio for c++ - c++

Usually, I place all the assets I need in the project folder, and whenever I run it using the Visual Studio debugger, it runs fine. But when I run the .exe file using the command line, or by just clicking on it, it has problems loading the files. The only way it can load the files is if copy all the resource files in the folder that my .exe application resides in. How could change where Visual Studio looks for the resource files when I run it using the Visual Studio Debugger so that it looks in the folder with the .exe in it, and not the project folder for all configurations (i.e. Debug and Release).

If I understand correctly you would like to move application dependencies into the Debug or Release folder.
You can do it using project property page (right click on the project and select properties). From list on the left side, select build events. There are three options, you can use Post-Build.
Have a look here : Visual Studio Post Build Event - Copy to Relative Directory Location

Related

Qt C++ Application deployment problems, used Visual Studio 2019 to create it

I just Build my Project and now when i click the executable file (.exe), i gives errors that some .dll files are missing, so i referred this page https://doc.qt.io/qt-5/windows-deployment.html which says that i can use Windows Deployment Tool, which is found in QTDIR/bin/windeployqt folder directory, but when i go to the path in the image c\Qt\5.14.1
i see that i have all these folders and all of them have bin folders, so to solve this i i went into visual studio , Extensions->QT VS Tools-> Qt options and this thing shows up ,where i got to know the version i am using
so, i opened command prompt and did this
After that, in my applications .exe folder, i see some more .dll files being added, but still i get the same errors
missing Qt5Widgets.dll,Qt5Core.dll,Qt5Gui.dll, i have all of those but the name ends with d, should i try renaming them ?
I have solved this by placing qt.conf file in my application's .exe folder
[Paths]
Prefix=C:\Qt\5.14.1\msvc2017_64
Defining Prefix in your qt.conf file allows it to find the qwindows.dll platform plugin when your app starts.

visual studio 2013 modify path variable when running .exe

I have compiled an exe file in Visual Studio 2013, and it depends on some external files to function. I want to keep those files in the same folder that the exe is in. When I run the .exe by clicking on it in file explorer, it loads the files fine. However, when I run it from Visual Studio, it is unable to run because the PATH variable does not include the directory with the necessary files. How can I configure my project to run the program with a modified path variable so that it can access the files properly?
As far as I understand you question correctly. I suspect that this is an issue related to the different directories when you execute. In Visual Studio (to my knowledge), you have a folder named Debug and a second folder named Release.
You may choose in Visual Studio to run the program in either debug or release mode. But you might not have the required files neccessary in both directories.
For example:
I've made a program that reads "Hello World!" from hello.txt, and displays this in the dialog window as a string.
If I store the file in the Release directory, the executable will run fine outside the IDE, when just launching the executable file.
However, if you run the application in debug mode through the IDE (Visual Studio), the program will not find the neccessary file. The program is looking for the file in it's current directory (Debug).
A quick fix to this is to copy the required files to the current working directory. Eventually have a duplicate set of files in both directories at all times.
Hope that I did understand you correct, and that my answer helps you. :)

Project cannot load image assets while running from visual studio IDE

I am porting an old visual studio C++ project. I have a data folder in the project directory that contains all the image assets. The project is build using an external make file.
My problem is, the project cannot load the asset files while running the executable from the VS IDE during debugging. However, if I execute the exe from bin folder, it can load the assets.I am assuming there are some kind of environment issue in the project, but could not figured it out.
Any clue?
My guess is that the program tries to access the assets using a relative path like ..\data\some.data. It works when you run it manually from the bin folder, because the current directory is set to the bin folder itself (the folder from where an application was launched) by default.
But when running projects from the Visual Studio IDE, parameters set under "Project properties > Debugging" tab apply instead. There is an option "Working directory", which defaults to $(ProjectDir), i.e. the folder where the project file resides.
Try changing that to the bin folder, or, if the resulting .exe file is placed directly there, easily just to the $(OutDir) variable.

How do I create an executable in Visual Studio 2013 w/ C++?

I can't find the exe file for my Hello World program that succeeded to work, and the program did not open as soon as it said it worked. I tried going to my documents and checking my project's folder. It was completely empty. Thanks for any and all help.
All executable files from Visual Studio should be located in the debug folder of your project, e.g:
Visual Studio Directory: c:\users\me\documents\visual studio
Then the project which was called 'hello world' would be in the directory:
c:\users\me\documents\visual studio\hello world
And your exe would be located in:
c:\users\me\documents\visual studio\hello world\Debug\hello world.exe
Note the exe being named the same as the project.
Otherwise, you could publish it to a specified folder of your choice which comes with an installation, which would be good if you wanted to distribute it quickly
EDIT:
Everytime you build your project in VS, the exe is updated with the new one according to the code (as long as it builds without errors). When you publish it, you can choose the location, aswell as other factors, and the setup exe will be in that location, aswell as some manifest files and other files about the project.
Click BUILD > Configuration Manager...
Under Project contexts > Configuration, select "Release"
BUILD > Build Solution or Rebuild Solution
Just click on "Build" on the top menu and then click on "Publish ".... Then a pop up will open and there u can define the folder which u want to save the .exe file and by clicking "Next" will allow u to set up the advanced settings...
DONE!
Do ctrl+F5 to compile and run your project without debugging. Look at the output pane (defaults to "Show output from Build"). If it compiled successfully, the path to the .exe file should be there after {projectname}.vcxproj ->

How to access resources when running app in Visual Studio?

in my application, I use various resources. I specified pre-build events to copy my resources to output directory. My directory structure looks like this:
/Debug/Models/
/Debug/Shaders/
/Debug/Textures/
/Debug/sfero.exe
/Debug/...
I want to access these resources relative to the .exe file and that works fine when I run the executable directly from Debug folder, but when I run it in Visual Studio, it is being launched in different directory, thus I cannot access my resources. Obviously, I don't want to copy my resources to location from where Visual Studio runs my application.
Any suggestions?
Thanks
You can either make your application logic smarter about searching for resources, or you can pass command-line parameters (see the Debugging area of Project Properties) when launching from Visual Studio, passing the path where to look.
The default current directory in Visual Studio is defined as $(ProjectDir) - which is by default the location of your vcproj file.
Go to your project's Properties -> Configuration Properties -> Debugging -> Working Directory and change it to $(SolutionDir)$(Configuration)\ or whatever your Output Directory points to.