Unable to load library issue with external dependencies - c++

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!

Related

Random error in exe_common.inl in Debug build

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.

C++ Program will not run due to Windows DLL issue

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.

Assistance including a basic SDK into a C++ program Dev C++

I have been making some applications that I would like to link to discord, specifically with Discord's SDK. The SDK comes with 64 and 32 bit x84 lib files, and a C++ folder full of the includes it needs, so I would assume C++ is supported.
However, I am very terrible at linking libraries or anything at that, and always run into issues when linking. I am using Dev C++ as my IDE, and my code is as follows:
#include <iostream>
#include "Discord/discord.h"
using namespace std;
void InitDiscord()
{
auto discid = 772671910668133376; //Not my actuall discord app ID, but real one does not make a difference
discord::Core* core{};
discord::Core::Create(discid, DiscordCreateFlags_Default, &core);
}
int main(){
InitDiscord();
cout << "Discord active";
while(1){
}
return 0;
}
and I am getting the error:
C:\TDM-GCC-64\x86_64-w64-mingw32\bin\ld.exe Discord Testing.o:Discord Testing.cpp:(.text+0x32): undefined reference to `discord::Core::Create(long long, unsigned long long, discord::Core**)'
for only the line discord::Core::Create(discid, DiscordCreateFlags_Default, &core); and not discord::Core* core{};
I am using C++17 and a newer TDM-GCC compiler, the same one that works for all of my other applications. I am including the .lib files and .dll files in the program's directory, and in the linker the only thing I am using is -discord_game_sdk.dll.lib which is a valid directory. I have also tried discord_game_sdk.dll.lib and putting the library in the same directory as the includes: Discord/discord_game_sdk.dll.lib. I have tried using both 32 bit and 64 bit libraries in all project and compiler directories with no change, and im sure this is something probably really simple, but nowhere have I found any example C++ discord programs or how to include their SDK.
If anyone could figure out what the problem is and how I can fix it, that would be very helpful and appreciated.
EDIT:
It appears that user4581301 was right, TDM-GCC and other Mingw compilers do not support .lib files, and will ignore them despite being linked. The SDK did not come with any other formats other than .dylib, .so, and .bundle.
This creates a somewhat new issue, I already have my compiler set up and cannot really switch to Visual Studio, so I need a way to convert .lib to .a somehow. A post here recommends http://code.google.com/p/lib2a/ , which requires a .def file, another file that did not come with the SDK, but apparently a program called gendef.exe that came with my compiler can create .def files from .dll files. That is indeed the case, however when attempting it I get the error:
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\bin>gendef.exe discord_game_sdk.dll
* [discord_game_sdk.dll] Found PE image
* failed to create discord_game_sdk.def ...
with no other warnings. Now I need to know if I am converting wrong, if there is an easier workaround, or if one of the other file types can be converted or used. Any suggestions at this point are welcome and appreciated!

MSVC: Unresolved external symbol "__imp_JNI_GetCreatedJavaVMs"

Edit2: Forgot to mention that I am trying to build a 64-bit application.
I need some help here.
For some reason I can't seem to find a way to make this external work and well, before you ask.
I've tried calling LoadLibrary:
// (temp)
// Load JVM library since it's being a dork
HINSTANCE hVM = LoadLibraryA("C:\\Program Files\\Java\\jdk1.8.0_172\\jre\\bin\\server\\jvm.dll");
if (hVM == NULL) { ... }
I have every lib folder included in VC++ Directory, I have also tried putting jvm.lib in same dir and just linking it through pragma comment: #pragma comment(lib, "jvm.lib")
But nothing seems to do the job. :/
Am I maybe looking at the wrong file to begin with? I've tried others like jawt.lib as well.
Edit: I get the function from #include <jvmti.h> but there is no corresponding .lib or .dll file. And every similar function comes from jvm so if it's not that one, which one is it? I'm lost.
My bad, I thought it worked for both 32-bit and 64-bit applications but seems like it only works on 32-bit applications. (Was using a 32-bit JDK install and in my haste I did not realize that.)

AVG Access Denied warning when running the simplest C++ program

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.