This code will run on your machine, but not on mine:
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> vv;
vv.push_back(1); //<--- without this, everything works
cout << "X\n";
return 0;
}
The reason, is that it appears my windows machine is missing a (or has a conflicting) specific DLL related to Vectors which is causing my other projects to crash without a report if I use vectors.
However, what's even more entertaining is:
If I comment the push back line, it executes normally without a crash.
Other programs work completely fine as long as they avoid vector, as in using list or an array.
GDB Reports "During startup program exited with code 0xc0000139." Which means it couldn't find the dll it wants. Looking through the dependencies of my executable with Dependency Walker is rather inconclusive, I can't tell what is wrongly missing and what is normally missing among the dlls.
It could also be that there is a second dll that is conflicting with it (like I downloaded two different compilers). Investigating with Process Monitor informs me that instead of using the MinGw64 files located in the MSYS2 folder, the process uses the dlls inside of my ProgramFiles/Git/mingw64/bin location.
So it could be an issue? But Process Monitor doesn't tell me why or what is causing the process to exit unsuccessfully...
How would I get Windows to use the dlls in MSYS2 instead of the Git location? The solution that the post I linked above says is to remove the "erroneous dlls." But I can't just remove dlls that git uses?
Also, how am I guaranteed that switching to the dlls within MSYS2 is going to fix my problem? I just want to use vectors lol, how hard does this have to be?
Other solutions include leaving this spyware infested OS and enter the world of Linux, but that's a huge change.
Related
I am using VS 2022 Community Edition (v17.3.3) to build wxWidgets application (v3.2.0) using C++ (v14.3 - Features from Latest C++). The windows SDK is using the latest installed (10.0.22621). The project is also using C++ modules.
The Debug build succeeds but when I run the project's exe file at random it throws the exception (Access violation reading 0xFFFFFF (ucrtbased.dll)) in exe_common.inl at the following line:
__scrt_current_native_startup_state = __scrt_native_startup_state::initialized;
After a few more compilations (by just making minor changes to trigger a compilation) it succeeds and the exe runs correctly.
I wonder if there is any settings that might be causing this random error. Btw, I am using Win11 but same thing happens on Win10 as well.
Thanks in advance.
EDIT 1:
The project is using boost libraries and at startup boost/json (boost/json is used in other parts of the project as well). Debugger shows that after the following line the above error happens:
static allocator_arg_t allocator_arg = BOOST_CONTAINER_DOC1ST(unspecified, *std_allocator_arg_holder<>::dummy);
There were a few things needed attention:
Discontinued use of wxSQLite (the library was not maintained for over a decade),
The main frame was a singleton data structure, not anymore, and not deriving from wxMDIFrame anymore.
All unnecessary (a chain of them) #include removed.
Inclusion of <boost/json.hpp> in a few files were removed and now using #include <boost/json/src.hpp> only in one .cpp file. However, the project still uses inclusion of <boost/json/value.hpp> in multiple .h files.
All uninitialized pointer variables and others were initialized.
#1 and #4 were especially pointed by the debugger. It has now been more than a few days and haven't had the problem since then.
I had compiled a simple hello world program in C with the MinGW compiler using the command line. As it had finished compiling, windows defender popped up and detected a virus (Trojan:Win32/Fuery.C!cl).
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("Hello World");
return 0;
}
https://imgur.com/a/05yDjw5
I had taken action on this (Removed) as windows defender suggested, but when I compile again the same happened, multiple times.
I had downloaded an AntiVirus (Malwarebytes) and scanned my whole system and it detected some registry key errors, but not this.
I've tried compiling C++ files too, but windows defender did not detect any virus there. This only happens when I compile in C.
I've also tried checking the compiled executable at VirusTotal.
https://www.virustotal.com/gui/file/476d47215dad80db49c9fd508ab5e10e5aeb5b623248ca156830a28b70affe5f/detection
I tried CodeBlock's MinGW compiler and 0 engines detected it. (Same C file)
https://www.virustotal.com/gui/file/8ba4b0fa24b1b6b69152acce2353fcca8447bbecbfc4e5ec48d33cc75d94f2f1/detection
EDIT: I deleted the path variable of C:/MinGW and added CodeBlock's MinGW compiler. I then used the command line to compile the same C file again and had uploaded the .exe file to VirusTotal. This time, 0 engines detected. So I have come to the conclusion that, the MinGW compiler that I had installed was creating this problem.
https://www.virustotal.com/gui/file/34d383f6c09f897d8c9a44ed0e7850574320e50fdf439eeb1f06705fdcc95386/detection
I don't know why this happens. Is there a malware in my computer that affects my C programs or is this a false detection?
There is no malware, it is a false positive. The executable generated by your version of MinGW looks very similar to a particular virus.
To avoid the problem, add the directory where you build your code to the list of exclusion in the antivirus.
Also consider using mingw-w64 instead of mingw.org .
I came across with the same problem, compiler tdm gcc v9.2.
The following compilation triggers a warning (kaspersky).
gcc temp.c -o temp.exe
The following does not
gcc -O3 temp.c -o temp.exe
Where temp.c is
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("mod %4d, %4d is %4d\n", a, b, a%b);
return 0;
}
The same code with g++ passes the test with both compilations. The antivirus software does not detect the same virus elsewhere but only in temp.exe (first compilation).
I may have solved my problem.
This is what I did: I removed the PATH Variable of C:\MinGW and added CodeBlock's MinGW compiler (CodeBlocks/MinGW/bin). I used the command line to compile the same C file, and had uploaded the .exe to VirusTotal. No engines detected this file!
https://www.virustotal.com/gui/file/34d383f6c09f897d8c9a44ed0e7850574320e50fdf439eeb1f06705fdcc95386/detection
So I have come to a conclusion that, MinGW was the compiler that was causing this problem. I have removed it.
However, I am not quite sure if this problem is FULLY solved. There is still a possibility of malware affecting my executable (or perhaps not). I cannot be sure.
If anyone has any answers, please comment or answer
I ran into this after installing MinGW on 01-08-20(dd-mm-yy).
For me it was also Windows Defender, the way to - hopefully temporarily- get rid of this is to add an exception for the folder your compilation output will reside in.
The Microsoft website states these steps to add an exclusion:
Go to Start > Settings > Update & Security > Windows Security > Virus & threat protection.
Under Virus & threat protection settings, select Manage settings, and then under Exclusions, select Add or remove exclusions
I had a similar problem. I figured out that the following dll was missing: mingw32-libmingwex-dll. Once I installed it via "MinGW Installation Package", I didn't have the problem anymore.
I hope this can help others.
Since you wrote that program and you know it isn't actually a Trojan, it's obviously a false positive. You should submit the file to them at https://www.microsoft.com/wdsi/filesubmission so they can figure out why it's triggering the false positive and fix it. (If it happens with everything you compile, just sending them one will suffice.) In the meantime, you should add an exclusion to Windows Defender for the folder that you compile your executables in.
A number of answers to this exact error have been put upon this website but I am quite the beginner to C++ and Code::Block so i'm afraid I do not understand them.
I have been following a very simple C++ tutorial that started me out with one simple program that I was told to copy and paste into the compiler.
#include <iostream>
using namespace std;
int main()
{
cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
cin.get();
return 1;
}
I actually did not write any of this code so my own syntax errors cannot be an issue. Basically that means I'm out of ideas for troubleshooting. Any ideas as to why I can't run this?
Okay so saving the file as a .cpp worked for the building, but when my program actually runs nothing appears in the menu that pops up in which, I assume, the text is supposed to appear. Again, I'm decent at troubleshooting but this code has been confirmed to work by thousands of others and there must be something else wrong.
Save your file in .cpp format instead of .c format which is default for Code::Blocks. Your workspace(that is the file where you saved this code in) will be renamed to xyz.cpp and you can easily check this fact in the tab.Furthermore, change the cout and cin statements to std::cout and std::cin.
Just to make sure we are on the same page.Goto Settings>>>Compiler.Selected compiler should be GNU GCC compiler. Goto Toolchain Executables tab and autodetect the compiler's installation directory (should be something like CodeBlocks\MinGW).
Code::Blocks compiles using some built-in .dlls and i have sometimes found it needed the dll in the folder with the compliled .exe
if not that, try the console application template
i use TDM-GCC it compiles fine.
I have created a C++ *.dll in VS 2013. This runs fine on my development machine, however is throwing an error when run on a clients machine.
Here is the cpp file.
#include "stdafx.h"
#include "EasyDLL.h"
using namespace System;
double WINEXPORT EASYDLL_GetServerDateTime(int clientServerTimeDiff)
{
System::DateTime clientDateTime = System::DateTime::Now;
System::TimeSpan duration( 0, 0, clientServerTimeDiff );
System::DateTime serverDateTime = clientDateTime.Add( duration );
String^ strTemp = serverDateTime.ToString("yyyyMMddHHmmss");
double result = double::Parse(strTemp);
return result;
}
I believe the reason is, the external dependencies don't exist on the client's machine.
I don't have much experience with C++.
Lead up to question:
When you compile (and I'm just compiling in debug at the moment), there is a whole bunch of header files in the external dependencies and a dll (mscorlib.dll).
The mscorlib.dll exists in the same place on the client machine, so I'm kind of discounting that as the problem, but the headers do not exist.
Question:
Do I need to ship these headers off with the dll I've created or should they be compiled into my dll?
Here's a screenshot of some of the external dependencies. Most of them seem to be in the project by default when the project was created.
EDIT:
After changing the project to release it seems to be running on another machine as well as my dev machine, have to wait untill tomorrow to test on the client's.
Although it has worked so far, I checked out DependencyWalker and got the following when looking at my dll, is this anything to be worried about?
You don't need to ship the headers with the DLL. If Mats answer doesn't solve it you might want to try using this tool: http://www.dependencywalker.com/
You can "look inside" a DLL that way. From my experience, best run it on both machines i.e. on the dev machine and the client machine because what might look like an error on the client machine, may also exist on the dev machine, thus discounting it as the problem.
Good luck!
I am running a very simple C++ program:
#include <list>
#include <vector>
int main(int argc, char **args) {
}
I go to the command prompt and compile and run:
g++ whatever.cpp
a.exe
Normally this works just fine. It compiles fine, but when I run it it says Access Denied and AVG pops up telling me that a threat has been detected Trojan Horse Generic 17.CKZT. I tried compiling again using the Microsoft Compiler (cl.exe) and it runs fines. So I went back, and added:
#include <iostream>
compiled using g++ and ran. This time it worked fine.
So can anyone tell me why AVG would report an empty main method as a trojan horse but if the iostream header is included it doesn't?
UPDATE:
I added a return statement to the main method and now I find that I only get the error if I return 0. Any other return value and it seems to work fine.
What's going on here?
You're not the first person to encounter false positives by antivirus software.
What probably happened is that the antivirus heuristics tripped up on the standard runtime libraries present in your programs, since malware uses them as well. Of course, legitimate software uses them too! The fact that it didn't trip up on iostream probably means that iostream isn't very popular among malware writers.
If you only want to overcome the problem as fast as possible,
just put the folder of the executables into AVG's whitelist.
My preferred steps:
For safety's sake, you should send your executable
to an online virus/malware scanner like these:
www.virustotal.com : VirusTotal - Free Online Virus and Malware Scan
virusscan.jotti.org/en : Jotti's malware scan
if they report 'false positive', then insert the path of the compiled executables
into AVG's whitelist,
so it doesn't scan that folder.
I'm not conversant with AVG, but every antivirus
has an option to exclude files from scan.
If you're brave enough, debug the executable and find the causing call.
An alternative solution may be to virtualize a lightweight linux system,
install gcc (with g++, of course) on it, and use that "g++ dedicated environment"
to
develop your commandline apps.
// The 1st step is a sum-up of this conversation.
// If you send me the source and the 'infected' executable that you compiled, then I'll check it.
// The missing return statement in the (C++) main function means returns 0.