Two days ago I was working on a C++ project using OpenCV, when suddenly my project couldn’t run anymore!
I just have changed my OpenCV dlls to parallel version and ended up with this Error: "The application was unable to start correctly (0xc000007b). Click OK to close the application." every time I tried to run my application.
After some hours of hard search I found that 0xc000007b error didn’t come from an exception in my code or even OpenCV dlls. I found that the error is just wrong configurations and the solution is easy, so I decided to write this article to show you how you cans solve this error permanently.
0xc000007b error comes mainly from mixing up 32bit environment with 64bit one, that is you have an 32bit application that tries to load a 64bit dll.
To see exactly who cause this you must examine your application dependencies carefully.
I used a free portable program to do this: "Dependency Walker". After you download it you can open any PE file (exe, dll, …)
Open your application executable file (in my case "testopencv.exe") with dependency walker, you sould see something like this:
As You can see, dependency walker shows all dlls my application depends on, and all dlls these dlls depends on and so on…
Now you must check these dlls to see which one is 64 bit? If your application works fine you should see nothing, but when your application throws 0xc000007b error that means you have at least one 64 bit dll in these dlls.
In my case as you see, my application depends on cv2010d.dll which depends on tbb_debug.dll which is 64bit dll (notice the 64 number near its icon). You can see the properties of any dll to find its path, my tbb_debug.dll lies on: "E:\Intel\Compiler\11.154\tbb\intel64\vc9\bin".
But why cv2010d.dll links to 64bit version of tbb_debug.dll instead of 32bit one? and how can we change that?
The answer is that most exe or dll have it is dependencies names only not their paths (that is what we called dynamic linking). So finding the real path of these dependencies done in runtime, and in our case that cause the problem.
When I run my application it tries to load cv2010d.dll which tries to load all of its dependencies including tbb_debug.dll. System tries to find tbb_debug.dll 32bit (because my application is 32bit) but when it can’t it tries to find 64bit version and it can, so it tries to load it and here is the error comes from.
To solve this I remove "E:\Intel\Compiler\11.154\tbb\intel64\vc9\bin" from the PATH variable, so when I tries to run my application system can’t find any tbb_debug.dll (neither 32bit nor 64bit version) so it throws a new error now says that tbb_debug.dll is not found.
The last step I made was coping the 32bit version of tbb_debug.dll and but it near my application executable file so now when system tries to load tbb_debug.dll it will find the 32bit version of it (also dependency walker will do that so there isn’t any 64bit dll in my dependencies now) and my application comes back to life again.