Windows Defender/Security deletes my "hello world" program - c

I'm trying to start a new C project using BearLibTerminal, compiling with gcc.
I'm able to compile the hello world, but when I try to launch, Windows Security gives an error, which reads
"Operation did not complete successfully because the file contains a
virus or potentially unwanted software."
Shortly after compilation, whether I attempt to run or not Windows deletes the executable.
I can of course disable Windows Security real-time protection, but this seems like a bad workaround. Does anyone know what could be changed so that Windows doesn't think my program is a virus?
Here is the code:
#include "BearLibTerminal.h"
int main()
{
terminal_open();
// Printing text
terminal_print(1, 1, "Hello, world!");
terminal_refresh();
// Wait until user close the window
while (terminal_read() != TK_CLOSE);
terminal_close();
}
and this is the makefile:
gcc -IC:/foo/include -LC:/foo/bin main.c -lBearLibTerminal -o test.exe
Thanks kindly for the assistance.
EDIT: I seem to have fixed the problem. For some reason, the version of MinGW found here, which is where I was directed to from mingw.org, causes things I compile to be detected as a virus. I removed MinGW completely, and downloaded the version found on SourceForge, and I no longer have the issue. I have no idea if the compiler was somehow compromised, or if Windows Security was just looking out for things made by a specific version of MinGW, but I would note that the version of "Hello World" from the first compiler was 4kb larger than the version from the SourceForge compiler, and likewise the installer was around 6kb larger too.

As a temporary fix you can exclude your compilation folder from Windows Defender.

Related

VSCode Microsoft C/C++ Extension Using Old MinGW System Path

I'm trying to run a simple Hello World C program in VSCode, on Windows 10, to test whether things are going fine or not (I previously had to reinstall the OS). So this is the code:
#include <stdio.h>
int main()
{
printf("Hello World!");
return 0;
}
Should be simple, and it should run perfectly well, I thought. I tried it with these options, which I assume was from the Code Runner (by Jun Han) extension. When I try selecting the "Run Code" option, everything works well, and the code runs perfectly. When I tried the "Debug C/C++ File" or the "Run C/C++ File" option, however, this was what I got.
* Executing task: C/C++: gcc.exe build active file
Starting build...
C:\Compilers\MinGW\bin\gcc.exe -fdiagnostics-color=always -g D:\Alfred\Studies\College\Skripsi\resources\preparations\CTest\HelloWorld.c -o D:\Alfred\Studies\College\Skripsi\resources\preparations\CTest\HelloWorld.exe
The system cannot find the path specified.
Build finished with error(s).
* The terminal process failed to launch (exit code: -1).
* Terminal will be reused by tasks, press any key to close it.
Worth noting here that C:\Compilers\MinGW\bin\gcc.exe is my MinGW directory in the system path before I reinstalled the OS. I'm not sure why it pulls that specific path, considering:
I've tested the MinGW installation on the reinstalled OS, and running the gcc --version command works on cmd,
The system environment variable has been set to the new path (C:/MinGW/bin),
If it's really a problem with MinGW paths, logically the "Run Code" option should also fail. Yet it doesn't.
Finally, I've also tried restarting the laptop, reinstalling MinGW, reinstalling VSCode (along with deleting the .vscode folder in %USERPROFILE% and Code folder in %APPDATA%), but this problem still persists.
I've been looking for the possibility as to why for hours now, yet I haven't managed to. Was hoping some of you could tell me what I overlooked here.
P.S.:
The only extensions I have installed are C/C++ by Microsoft and Code Runner by Jun Han.
Please bear with me if my question was missing some details - I have very little experience in asking questions here.
Edit 1: I've been told this was due to Microsoft's C/C++ extension, and not Jun Han's Code Runner. I have edited the title to reflect so.
The two options you mentioned are from the Microsoft's C/C++ extension: they use the C_Cpp.default.compilerPath setting to locate your compiler. You can change it either the settings GUI or in the JSON file.

Why does Windows Defender detect compiled C executables as viruses?

I'm using Visual Studio 2019 (Community Edition). I've never had an issue when compiling C++ code. I simply get the final executable and I'm able to run it without a problem. Recently I've decided to learn C and this is the C program that I'm compiling:
#include <stdio.h>
int main()
{
printf("Hello, world! \n");
return 0;
}
The file name is "main.c".
I haven't changed any of the default project settings and the project that I selected was "empty C/C++ project".
The code compiles fine but when I attempt to run the executable I get this error:
Unable to start program [path to .exe file]
Operation did not complete successfully because the file contains a
virus or potentially unwanted software.
I can resolve this issue by going to Windows Defender and manually allowing this detected threat but obviously the issue with this approach is that other people won't be able to run my C programs without them being detected as a virus.
Ultimately, I believe this problem is related to how VS2019 is compiling my program rather than Windows Defender because I'm able to compile C++ (and other languages) into executables that run perfectly fine.

.dSYM files generated from command line (Mac)

I just started coding in C, and ran someone else's Makefile with the default C compiler set to gcc. I am on Mac OSX 10.8 Mountain Lion and I believe I installed the compiler with "XCode Command Line Tools." After running "make" on command line, I get these annoying .dSYM files for each program. I read that these are debug files, but are they really necessary? Is there any way to prevent them from being generated from command line?
The -g flag to GCC will generate debug symbols. You may simply remove that flag from CFLAGS.
Yes, the dSYM files are necessary. Specifically, they contain the symbol tables that are included within Xcode debug builds; release builds put the symbols in this separate file. If you ever need to analyze a stack trace from a release build you will need this. And make sure you don't lose the files, because doing the build again, even if the source is absolutely the same, won't produce a usable dSYM file. Each build is given a UUID and that changes with each build, even if the source has not changed. (I guess it includes a timestamp or even a random number.)
If you throw away the dSYM files, then if you suddenly find your app crashing a lot, you may be sorry.
They're only necessary if you need to interpret locations in stack traces within a crash report.

Source file not compiled Dev C++

I just installed Dev C++ and I am learning C programming.
the code i used was
#include <stdio.h>
int main()
{
printf("Hello world");
getch();
}
I saved it as a .c file. When I compile it works fine, but when I compile and run it says source file not compiled. So I googled buncha things and came across this video on youtube which shows you how to fix it. I also saw other forums on google which suggest the same thing... However, after doing whats asked, Now I can't even compile my code. I get this error
Compiler: Default compiler
Executing C:\Dev-Cpp\bin\gcc.exe...
C:\Dev-Cpp\bin\gcc.exe "C:\Users\ubaid\Documents\C\Untitled1.c" -o "C:\Users\ubaid\Documents\C\Untitled1.exe" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
gcc.exe: Internal error: Aborted (program collect2)
Please submit a full bug report.
See <URL:http://www.mingw.org/bugs.shtml> for instructions.
Execution terminated
I have also used what is asked on this link, and still no luck..
http://learntogeek.com/miscellaneous/solved-source-file-not-compiled-error-in-dev-cpp/
I am using windows 8
I was having this issue and fixed it by going to:
C:\Dev-Cpp\libexec\gcc\mingw32\3.4.2
, then deleting collect2.exe
Install new version of Dev c++. It works fine in Windows 8. It also supports 64 bit version.
Download link is http://sourceforge.net/projects/orwelldevcpp/ .
I guess you're using windows 7 with the Orwell Dev CPP
This version of Dev CPP is good for windows 8 only. However on Windows 7 you need the older version of it which is devcpp-4.9.9.2_setup.exe
Download it from the link and use it.
(Don't forget to uninstall any other version already installed on your pc)
Also note that the older version does not work with windows 8.
This maybe because the c compiler is designed to work in linux.I had this problem too and to fix it go to tools and select compiler options.In the box click on programs
Now you will see a tab with gcc and make and the respective path to it.Edit the gcc and make path to use mingw32-c++.exe and mingw32-make.exe respectively.Now it will work.
The reason was that you were using compilers built for linux.
You can always try doing it manually from the command prompt. Navigate to the path of the file and type:
gcc filename.c -o filename
I found a solution. Please follow the following steps:
Right Click the My comp. Icon
Click Advanced Setting.
CLick Environment Variable. On the top part of Environment Variable Click New
Set Variable name as: PATH then
Set Variable Value as: (" the location of g++ .exe" )
For ex. C:\Program Files (x86)\Dev-Cpp\MinGW64\bin
Click OK
This error occurred because your settings are not correct.
For example I receive
cannot open output file Project1.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe: *** [Project1.exe] Error 1
Because I have no permission to write on my exe file.
After some investigation, and with Dr.Topaz's help, I have learned that you will want to confirm that the program set for g++ in the Compiler Options really does compile the source code. In my case, the C:\Dev-Cpp\bin\g++.exe program did not create an exe, but the C:\Dev-Cpp\bin\c++.exe program did. Either program appears to be intended to take the same arguments and options as GNU g++. I would love to find an actual doc on the Dev-C++ compiler programs, but I have not so far.
You can test the compiler program with a simple example like this:
C:\Dev-Cpp\bin\c++.exe hello.cpp -o hello.exe
Currently in 2021, the Dev-C++ site invites you to download either original Dev-C++ or a newer fork by a group named Embarcadero.
I decided to try the Embarcadero version and the experience was slightly better. The UI is still a tad dated, but the g++.exe program it came with was able to compile programs without issue. Again, take note of where the program is being installed, but in my case, the Embarcadero compiler programs were in C:\Program Files (x86)\Embarcadero\Dev-Cpp\TDM-GCC-64\bin.
Both original Dev-C++ and Embarcadero come with mingw-32 versions of the compiler programs that from what I see do work in a Git Bash console, with slight differences such as not recognizing a default locale when using the command std::cout.imbue(std::locale("")).
I faced this similar error, and none of the solutions worked.
so I tried to download the latest version from here, https://www.bloodshed.net/
I rerun the program.
and everything is now working correctly.
I was facing the same issue as described above.
It can be resolved by creating a new project and creating a new file in that project.
Save the file and then try to build and run.
Hope that helps. :)

Compiling with C.vim on Windows?

C.Vim works, as evidenced by the commands I've been using, syntax highlighting, and template. But I use \rc and nothing happens. \rr tells me that there is no .exe, and an Everything search tells me that it's not a directory issue.
In all the resources I've read, I don't see anything that says I need to point it to a specific compiler, though I've installed Visual Studio 2010.
How do I get C.vim to compile my code? I'm a relative beginner with Vim and C.
Edit: I've set the Windows Environment Variable to C:/cygwin/bin where I've downloaded and installed the GCC packages, but am still getting the same error.
Edit2: I've downloaded Msys and Mingw as well. I tried setting up Eclipse as well, following the instructions here. Running make from the command line tells me that GNU Make 3.81 is running. Running :make in Vim tells me:
shell returned 2
(1 of 1) : make *** No targets specified and no makefile found
Trying Eclipse, I get another make error:
make: *** No rule to make target `all'; Stop.
Edit3: I got Code::Blocks running, which is what I used to run. (It's been a while since I programmed, and even then I was a beginner.) I didn't really have to configure it at all, though I would still prefer to use Vim, so help is still much appreciated.
Edit4: running make vimFirst (vimFirst.c is my file) compiles! Running the program with :! vimFirst.exe works as expected. Now returning to the original question, how to do it with C.vim? It would be so much more convinient to type \rc and have the program compile and run, which is about 1/10 of the typing of the other method.
Edit4: running make vimFirst (vimFirst.c is my file) compiles! Running the program with :! vimFirst.exe works as expected. Now returning to the original question, ... type \rc and have the program compile and run...
Check your maps for \rc and \rr:
:map \rc
:map \rr
If no mapping exists, you might have no_plugin_maps or something similar set in your vimrc.
I think you'll get what you want if you set them up like this:
nmap \rc :make %<<CR>
nmap \rr :! %<.exe<CR>
If you're really familiar with Visual Studio and want to use nmake to build your code, you should check out the :compiler option. :compiler msvc will setup your makeprg and errorformat for nmake and Visual Studio's compiler.
I'm not sure what make is currently using to build your code, so I don't know what compiler setting you'd want.

Resources