App looking for an invalid dynamic library - c++

alt text http://img63.imageshack.us/img63/5726/screenshot20100125at124.png
I keep getting multiple error windows for an app i'm developing asking for ._libpal_bullet.dll when it should really be just libpal_bullet.dll. The weird thing is after I get all the error messages, the app runs anyway using the correct dlls that exist in the same directory.
How can i get rid of these errors?

You can use Dependencies Walker to step through the code to see who is invoking the call to the DLL. Maybe you have the ._libpal_bullet.dll included in your release configuration.

Thanks Extrakun, you indirectly helped me figure this one out.
I guess this happens when you copy code between OSes.
The problem was that there were duplicate files of these library names in the build folder. They were metadata files from OS X, which must have come over to the Windows side when I copied the folder to Windows. It's strange that they would be attempted to be executed even though they have different names to the proper DLLs.
Anyway deleting the files (they were hidden!) solved the issue.

Related

Windows C++ MFC migration: AfxGetThread Assertion. Why does win32u.dll load before mfc140d.dll in some cases?

I have customer code written for Visual Studio 6.0 MFC which has a simple GUI and launches an EXE with arguments. This code was ported from VS6.0 to VS2019 about 2 years ago and works in a production environment on several systems. We now have a new system where the code fails to function... and I'm starting to dig.
The code is throwing exception in appcore.cpp line 196
It is crashing at AfxGetThread() now that I have been able to get VS2019 to find "appcore.cpp".
This is new information.. I will be searching on AfxGetThread next... so this question likely to be a duplicate now.
One difference I have detected is the order where the Visual Studio 2019 debuger loads symbols. I can't say for certain that this is an indication of the actual DLL load order at runtime, but it appears to be. The screenshot below is the SYMBOL load order where a difference is detected between the working and non working instance of the application.
In the image below we have a Tortoise SVN Diff of two ASCII files. One is the DLL symbol load order on the left when the application works. The second is the DLL symbol load order on the right when the application fails to work. Line 7 is the divergance, where in the failig case the library win32u.dll is pulled in before mfc140d.dll.
The customer code uses some Apache log4cxx libraries which I need to investigate, but at this point in the load sequence I'm not 100% sure differences in those libraries or *.h files used at build time could influence the DLL loading order.
So this is the puzzle I'm looking at.
I will include some links to relevant StackOverflow questions that are similar in my search for an answer to this question.
Possibly Useful Links:
https://learn.microsoft.com/en-us/cpp/porting/porting-guide-mfc-scribble?view=msvc-170
The DLLs are searched in order in different locations: Standard Search Order for Desktop Applications
Most likely the DLLs on the failing machine are missing or they are in the wrong location, so Windows grabs something else.
Make sure all the dependencies are installed in the correct folders.
In this case, the crash in appcore.cpp was due to the code having 2 CWinApp derived objects in the code. And the crash occurs at construction time.
The first hurdle is to get VisualStudio2019 to find appcore.cpp and be able to step into this code. I browsed to C:\Program Files(x86)\VisualStudio and searched for "appcore.cpp". This provided the trail of breadcrumbs to get Visual Studio2019 the correct path when it asked for the file.
In my case the path is:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\atlmfc\src\appcore.cpp
The second hurdle was to put a breakpoint at the ASSERT point, as the FIRST time the program comes up, this ASSERT is OK. At least in my case... the first constructor of the CWinApp object succeeded. So in my case the offensive code which was unexpectadly constructing a CWinApp derived object ran first. Then the second iteration through the ASSERT would happen.
By placing a breakpoint at the ASSERT, you can re-launch and look at the stack trace of the successful object to determine if it's expected or not.
In my case there was a *.h fix required to get ancient Visual Studio 6.0 MFC code to build and link successfully. I don't have the exact secret, but it's essentially getting a *.h to specify the proper WIN_VER minimum windows version before afx.h is included. For the code that failed, an incorrect *.h was included that included the fix PLUS objects that derived CWinApp.
As near as I can tell, the reason this worked on some sites and not others was due to a regression in the code that was built on that particular system.
The other "strange" behavior was that on the system with the bad *.h include the DLL symbol load order was different. I was able to replicate this bad behavior on more than one system running the "bad" Exe code. Then I did the same on working *.exe code. The strange thing was that the "bad" exe had reasonably correct sources in the workspace. So there were source control issues leading to this belief that it worked on one node and not others.
The runtime behavior I was able to catch matched obsolete code committed to source control.

Why shows error message when generating application release

I have the following problem, when generating the release of my application, it shows me this message, even though I add the libraries you need, that message still appears, also try using the windeployqt.exe and it does not work, any suggestion would be appreciated .
I am using version 5.15.2 of qt
I was able to solve my problem, I was checking in the advanced configuration of the system and it happened that it had several values, in the PATH variable with paths to the Qt installation folder, so I deleted them all and with that I could solve my problem, thanks for your answers.
now the problem is with respect to the database, I managed to generate the executable, add all the libraries you need, it happens that it does not show anything when I run it.
The application is already running, but the data is not displayed, which it queries from the DB.

Compile program in VS without any need of external runtime dlls

This is somewhat an addition to this question (MSVCP140.dll missing).
I am trying to compile a program for a windows machine. Something huge to note here is I do not have the privileges to install software on it, but I may run executables.
Every time I run it on the windows machine in question I get a missing MSVCP140.dll problem. I have followed the solution of the question I have linked (which is static linking) and for some VERY odd reason I am still getting the error (even though I know this enabled the program to run on colleagues computers when they were getting the same error).
Is there anything more I can do that will make the program (for lack of better terms) fully portable? Any more settings I need to change in VS such that it will fully compile the libraries into the executable?
I am going to further stress the fact I have seen the solution to use static linking using the /MT option for compilation and I am still getting missing .dll problems.
I tried copying MSVCP140.dll next to my executable and it did solve the issue, but there is another missing .dll and I cannot incrementally add .dlls until the program starts working. I am happy to bundle all the .dlls with the program if that is the only solution but I would like to know which ones are needed so I don't have to copy my entire system32 folder out of desperation.
Have a go at using dependency walker to figure out what dlls you need, and why you need them. This can be enlightening, and lead to a path of cutting out many dependencies by using alternatives. If you are sure you aren't importing certain functions at consumer runtime (e.g. you are only importing them for debug purposes), then you can choose to delay load them.

Run time error on executing the exe manually

I have a Qt application, which runs fine when I execute it from Qt Creator. However, on running it by manually clicking the generated exe, I get the following error :
I would understand if it would ask for missing DDLs (which I could then place in the same folder). But how should I proceed to handle this (in general) ?
P.S. It is not giving any line number in my source code which I could try testing this assert for. I tried using the release mode as well, but the same error.
We don't know what the problem with your code is; you'll need to use a debugger to find that out. I think that the pre-built Qt libraries that you download come with debug symbols, but if they don't, you can always build Qt yourself to get them using the -force-debug-info configure option.
You can also use DebugView to see debug output of deployed applications.
However, in general, you should use the windeployqt tool that is included with Qt.
The Qt for Windows - Deployment page has more information about deploying Qt applications to Windows machines, but windeployqt should do everything you need.
My qml files were not getting deployed properly and thus this error (this assert is probably on the variable storing the main qml file name, i.e. it should not be an empty string, which in case of missing main.qml, it was). Placing the qml files at correct paths solved the issue.
Also, as #mitch has pointed out in his answer, use windeployqt to find out the dependencies. Although, I have also realized that it doesn't cover all the dependencies (MSVC runtimes for example and other compiler related files sometimes). In that case run the dependency walker and place the missing files manually along with the exe.

C++ Linking and COM Registration issue

I've added a new library to my application (multiple projects-DLLs) - SQLite, to perform some in memory caching. There is just one library/project that is affected by this change - Lib1.
A build goes through fine. All libraries are built successfully and no errors are reported, including a couple of Com Objects.
If I try to register the com objects, I get the The DLL could not be loaded. Check to make sure all required application runtime files and other dependent DLLs are available in the component DLL's directory or the system path. message. But all the libs are at the same place. And all are in the path. A copy of this project builds and registers fine (without the few changes made for SqlLite ofcourse). Dependency walker reports no issues
Oddly, if I try to register the DLL of the com object (using regsvr32) it works fine. Also, I have another library, which is dependant on Lib1 (not on SqlLite) which also cannot be loaded.
Any ideas?
Thanks,
A'z
You can use Process Monitor (http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) set to filter process name regsvr32.exe in order to see all file and registry access.
Always use full path to your-com-dll when you issue regsvr32 commands, if you have the same dll somewhere else in path (for example c:\windows\system32) regsvr32 will use the other dll and not the one in your current directory.
Another trick would be to use "rundll32 your-com-dll,DllRegisterServer". In case of missing dlls it will tell which dll is missing instead of just saying that LoadLibrary failed.
Edit:
What do you mean by "If I try to register the com objects"? How are you doing this? I'm asking because you say that regsvr32 on the dll which actually implements these com object works fine.
Use the dependency walker tool to figure out what other dlls the COM server relies on. Then check the executable paths that is set in Visual Studio (Tools -> Options -> Projects -> Directories (I think)). Note that VS does not use the system PATH environment variable - it uses what is set in the options page so if the path to the dependencies is not listed there, the registration would fail, even though if you used regsvr32 from the command line it would succeed.
And so, the plot thickens!!!!
I've actually narrowed down the to the line of code that causes this linking problem.
In the modified library (LIB1) I've added a new class A1 which inherits from an existing class A.
When I change an existing class B which used to inherit from A to now inherit from A1 - this is when the problem is caused. Class B is in a lib3.
I've verified that just when I change the inheritance, only then the problem occurs!!!
I've used file-mon on regsvr32 when loading successfully and when failing. I stuggle to find the difference! Tomorrow morning I'll try Process Monitor and see if it helps.
Still desperate for help,
A'z
hmm... as Christian asks, how else are you attempting to register the objects if regsvr32.exe succeeds?
the rundll32.exe advice is also good. have you tried stepping through DllRegisterServer in a debugger to see precisely when it's failing? this sounds like a potential runtime failure if depends.exe isn't revealing anything.
btw, when i google for that exact error text i see: http://social.msdn.microsoft.com/forums/en-US/sqldataaccess/thread/402c1767-cf1d-42f0-aec9-e0169dbf1083/, but I assume you've probably already done this search and found it not helpful :)