VSCode C++ Compiled exe was infected with Win32:TrojanX-gen[Trj] - c++

I am setting up VSCode for C++, made some simple code (test.cpp) to test if things are working.
#include <iostream>
using namespace std;
int main(){
cout << "Hello";
}
When I click run code the console says "Access is denied" and my antivirus pops up and says the test.exe and tempCodeRunnerFile.exe was infected with Win32:TrojanX-gen[Trj].
What exactly is Win32:TrojanX-gen[Trj] and how do I grant access so my antivirus wont pop up?

I had this issue as well. Its simply because some antiviruses think that unsigned .exe files (which is the output of your CPP file after you compile) are some sort of malicious file. You do need to exclude this from your antivirus, and your best bet is to first find out which antivirus you have, and second go to the "exclusions" list and add either the folder you're working with, or the file itself. I'm assuming you have AVG lol Exclusions can be found in the settings of your antivirus. Right click on the icon and see if you can go to preferences or settings. Then look for exclusions, or even an advanced setting option, and keep looking for something along the exclusions nature.

Just add an exception to the folder which contains your c++ code. (The whole folder). It did the job for mine ^-^

Related

Code Blocks "It seems like project has not been built yet. Do you want to build it now?"

Code blocks bee working fine for me. But yesterday whenever I try to compile a small program a window appears showing
It seems like project has not been built yet.
Do you wan to build it now?
I also found similar questions but in all of them not a single program is working. But in mine "hello world!" program and some other programs are working.
This is the code:
#include <iostream>
using namespace std;
void print(int b[], int s);
int main()
{
int a[5] = {1,2,3,4,5};
print(a, 5);
}
void print(int b[] , int s){
for(int i = 0; i < s; i++){
cout << b[i] << endl;
}
}
I installed code blocks in another computer and it's working fine.
I'm still learning C++.
What if I tell you that you should build your program to run it?
Wikipedia says:
In the field of computer software, the term software build refers
either to the process of converting source code files into standalone
software artifact(s) that can be run on a computer, or the result of
doing so. One of the most important steps of a software build is the
compilation process where source code files are converted into executable code.
It may be possible that your compiler is not linked properly to C::B or many other errors will be shown after you try to build your project, but for now (unless you post any build log) - you have to build your application in order to run it.
In CodeBlocks when a program is part of a project, it needs to built so that the compiler puts together all of the individual parts of the project.
If you do not want it, just make it a stand-alone program by opening it out of the project.
Pressing F9 would do just fine.
Solved , Anti-virus was deleting the .exe file for some reason. I put the project file folder in the "exclusion list" of anti-virus (or you can deactivate the anti-virus)
This happens if you add a New File to the project and try to build-run the code.
The solution is to create a new file outside the project and then right-click on the tab (where the name of the file writes, followed by .cpp) and select Add file to active project. In the pop-up GUI, check the Debug and Release options and hit OK. Now if you build and run, you will no longer have the message saying “It seems like project has not been built yet. Do you wan to build it now?”.

When debugging a visual c+ program, the file specified can't be executed

I made a simple hello world program. I clicked on "Start Debugging" and the window showed "Project is out of date. Would you like to build it?" As I click on "yes", the next window shows "There were build errors. Would you like to continue and run the last successful build?". I choose yes again, and it shows this window: (attached screenshot)enter image description here
There were build errors. Would you like to continue and run the last successful build?
The only correct answer to that question is "No". If you clicked "Debug", you obviously want to debug the current version of the source, not some stale old version that won't match what you're seeing in the editor.
Disable this nonsense message in Tools → Options → Projects and Solutions → Build and Run. For "On Run, when projects are out of date", set it to "Always build". For "On Run, when build or deployment errors occur", set it to "Do not launch".
I cannot think of a reason why you ever want the other options as default settings. If you want to launch an old, stale build, you can always do so manually.
I choose yes again, and it shows this window: "The system cannot find the file specified."
Yet another reason why this is a stupid setting. The second one in particular, the one that controls Run behavior when build errors occur.
What happens is, when you tried to build the project, the first step was to do a clean, which effectively means delete the old files. With the old files gone, it kicks off a build. The build fails, you get an error. You ask it to ignore the error and run an old version. But wait! The old version got deleted at the start of the build, so it no longer exists!
If a build fails, return to the IDE, fix the errors, and then relaunch to rebuild.
Bonus: The build error that you're getting is "fatal error C1010", which is a rather silly error that can be very confusing to those unaccustomed to Visual Studio. Basically, what it's telling you is that because you are using precompiled headers (the default for new projects), the very first line in every source file needs to be the inclusion of your precompiled header. By default, it is named stdafx.h, so the first line in your code file should be:
#include "stdafx.h"
This should go before you include the system header <iostream>. The precompiled header must be included at the very top of the file, or you'll get a build error.
If you do not like that, then you can turn off precompiled headers:
Right-click on your project in the Solution Explorer, and choose Properties.
At the top, click the "Configuration" combobox and select "All Configurations".
Expand "C/C++" in the tree view, and select "Precompiled Headers".
Set the top option, "Precompiled Header", to "Not Using Precompiled Headers".
Sorry: your last successful build was deleted earlier - possibly as a result of an attempted compile/link. You need to fix the source code that you've got now before you've got anything to debug...
It seems to appear that some .dll files are missing for the debug mode for many users.
You don't need to run the debug mode for this, if your program works on normal running, then let it run.
I also can see that you wrote void main() but in C++ the good syntax is int main() and terminated by a return 0; instruction. By the way, think about letting at least a space between #include and the libraries like <iostream> here.

Code::Block not creating a Debug Build?

I have had this problem with Code::Blocks that when my project is still overly small (even 10 lines long), and I go to build "debug", the file will not be created. It doesn't tell me this in Code::Blocks. Basically, I go to hit play, and it will ask me to build my project even though I had clicked the "build" button about 2 seconds before...
It works fine with release build, however...
#include <iostream>
using namespace std;
int main()
{
cout << "Hello" << endl;
cout << "World!" << endl;
return 0;
}
Even a program as simple as that does work in release build, but not debug build (the file gets deleted).
Have I got something wrong with my settings? Note it was like this ever since I downloaded it, and I had no idea what was wrong (as it does debug build by default, so I didn't know I could use release build)
Anyone know?
Edit: yes, the file is part of a project file
Make sure you selected 'Console application' when creating the project instead of 'Empty Project'.
Also, when you create the project from new, make sure that the:-
'Create "Debug" configuration'
is enabled, and has valid paths showing etc.
On the previous dialog, where the new project tool asks for folder paths etc to put stuff, make sure you give it somewhere valid (that exists) etc, or make a new folder for it.
I've just built and run your bit of code as Debug and Release just fine, in C::B 16.01 on Windows. As a "Console" application. Using the defaults, other than I created a new folder for it all.
Regards.
DJB

Codeblocks cannot create output directory

I'm using Code::Blocks 12.11 in Widnows XP. I've been learning C++, so I haven't been working on any specific projects, just individual files. I'm trying to debug one of these files, but found from this question that I needed to be in a project in order to debug. So, I created a project for all of my C++ practice files. Now, when I try to debug (or run) the program, Code::Blocks gives me this error: "Can't create output directory bin\Debug.
When I remove the file from the project it still gives me this error. What can I do to try to fix this so that the program can run and debug?
Additional information:
In Settings>Compiler>Global Compiler Settings>Compiler Settings>Compiler Flags, I have enabled "Produce debugging symbols [-g]". This is something that a lot of other resources I've checked have mentioned.
Also, under Debug>Active Debuggers, I've tried using both debuggers, both of which produce the same error message.
Why don't you try to remove the entire project directory, create an empty project and then place the source files one by one into the project. Beware if you have a main() method in each of your source files.
Well, a friend of mine was getting the same error. So I decided to check it out.
I my case, the error was because of the account user name.
When I checked, the output directory while creating the file and the one in the error being shown, were different.
When I checked, I created an user account name with "$aaa$", and I got the same error.
and I noticed that the error was because of the "$" sign. (Probably).
So, I guess the problem is with the user name. Try changing the user name to something simple.

Where does Xcode create .txt files to?

http://www.cplusplus.com/doc/tutorial/files/
I just finished executing this but I didn't get any file on my desktop.
So where does the .txt file get placed on my computer?
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
Damn... I've seen this post never answered many times..
Here's the solution
In your project navigator when you're working in your current project there are many files. Try products (if I remember) and look for the executable file. Now go to the properties inspector or whatever is called. (Right side of your Xcode.)
There you will find somewhere a part called PATH the path that is written over there. It's the path where the executable runs. That means there is where you'll find all the files you create with your program.
Try it... that's how I manage and look my .txt files since sometimes I wanna give them some kind of formatting.
I hope I've solved your problem... cheers! ;)
Click on the executable in the Products tab on the left hand side, and you should see the path to it displayed on the right in the utilities section. This is where they are saved. On my computer this path is:
/Users/myName/Library/Developer/Xcode/DerivedData/CurrentXcodeProject-adsnvetbleazktcgitfymfcbhkkt/Build/Products/Debug/filename.txt
In the "current directory", meaning the working directory of the environment from which you ran the executable.
I can't tell you what that is, but in basic cases it may be the directory where the executable is located. In many other cases it may not be.
Performing a search for the file on your hard drive will reveal its location to you.
Right click on your product and select "Show in Finder". Thats opens the path to where the output files go. Also you can add input files there to be read in by your program.
Found best answer here:
File creation in C++ on Xcode
Basically you can specify a known directory so that all files created go there.
If you are on Mavericks Right click in your user folder with your documents and pictures and stuff (~/Users/yourusername)
Now right click and view options. Check "show library". Now follow to the path that the first user above said.
What I've always done when an application saves a file and I don't know where... is just go back to that application, and hit File>Save As...
So re-open Xcode and go to the "File" menu, and click "Save As..."
It will show you the same directory it just saved to.
I have checked the "Current Directory" but I believe I have to specify the location. Not even
~User/Desktop
will work.
What I do is create an empty file with a the correct name on my desktop then drag that file into my Xcode project to get its path. I then delete the file.
Same with adding files to my project. I can add them from the File menu, but I will need to drag them in to the spot in my code where I want to reference them.
It is kind of convoluted but it is the only system I have.
Some of the answers are confusing. Here's the simplest solution.
1. Expand your Products folder on the left-hand side
2. Right click on the terminal icon(sorry I do not know what it's called)
3. Click show in Finder.
You should be able to see your output file in there.
" Where does Xcode create .txt files to? "
You can decide where you want: follow these->
" Product->Scheme->EditScheme "
chose options tab in the new popup "options"
"working directory" tick "use coatroom working directory" and locate the folder where you want.
The .txt file that you "create", or that you want too "read" has to keep in this folder.
In 2022, click on the project name in the "breadcrumbs" area above the editor. Select the correct thing in "Products", then in the right area, see "Full Path".