Error "The application was unable to start correctly (0xc0000142)" from the command prompt but not from Visual Studio - c++

I have a project that I build with CMake, which is composed of a library black.dll and an executable black.exe that depends on the DLL. The DLL in turn depends on libz3.dll which is an external dependency.
When I build from the command prompt using CMake I cannot run the executable because of the error "The application was unable to start correctly (0xc0000142)". The external dependency libz3.dll is correctly copied into the executable directory.
But, when I build the project from Visual Studio 2019 (making it use CMake under the hood as well), everything works properly (when I copy libz3.dll into the executable directory).
I've looked at the two executables with Dependency Walker to understand what's the different between the two but there are no differences (both show errors of missing strange libraries such as API-MS-WIN-CRT-RUNTIME-L1-1-0.DLL but in the case of the executable built with VS it seems to not be a problem).
I've also checked to be building for the correct architecture: both the executable, the library and libz3.dll are built for x64.
What can I check to understand what's going on?

Related

Building protobuf for Linux using VS2017

I have configured VS2017 to build Linux C++ by remote building on a Linux Mint VM.
I tried a simple C++ program and it compiles and executes fine, the thing is that now I need to add a generated protobuf source and the linking fails constantly.
On the Linux VM the protobuf generated files are building correctly and I was able to execute the gRPC examples.
The errors I get when I build from VS2017 are a lot of:
undefined reference to 'google::protobuf::internal'
and there is also this one
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Application Type\Linux\1.0\Linux.targets(262,5): error : Illegal characters in path.
I think this is a VS2017 remote compilation configuration issue, but I don't know what could it be.
Has it happened to you? Do you know how to solve this issue?
Thanks
SOLUTION: I the project properties go to Linker > All Options > Library dependencies and add: protobuf;pthread;grpc++;grpc
This explains the "Illegal characters in path" message.
Does protobuf link to any libraries on the Linux system? Assuming you're not using CMake, have you added the libraries andtheir path(s) to the Visual Studio project - Library Dependencies and Additional Library Directories.
This might help with specifying libraries.

Application compiled with VS2013 wants VS2005 runtime

I have environment where both VisualStudio 2005 and VisualStudio 2013 are installed. And I have strange situation with some of the projects. I compile such projects with VS2013 and when I try to launch them through Explorer or command line I get an error - "The program can't start because MSVCR80.dll is missing ...". Why msvcr80 when I compile with msvcr120?
What I tried:
Put msvc*80.dll to directory with executable. I got runtime error "R6034. An application has made an attempt to load the C runtime library incorrectly..."
Checked binary dependencies with Dependency Walker. I saw that binary has dependencies to VS2013 runtime, and there is no mention about msvcr80.dll
Launched binary with empty PATH. I gave no positive effect.
Launched binary on another 'clean' pc. And it worked all right with vs2013 runtime.
How can this be?
Thank you for all, you was right. I just forgot, that I have installed old version of my product. It was launched in background and used old versions of libraries. So when I ran my new application it tried to use libraries that already had beed loaded. In another way Dependecy walker didn't check already loaded libraries and looked only in PATH.
MSDN link about DLL loading - https://msdn.microsoft.com/ru-ru/library/windows/desktop/ms682586(v=vs.85).aspx

how to deploy simple boost program written in visual studio on other computers

I have written a simple program in C++ that uses the boost filesystem library to organize some files. I am using the Visual Studio 2013 Express for Windows Desktop IDE. I would like my program to run on other computers without an installer or anything else. The user should be able to just download the program and click on it.
I built my program in Release mode and it works on my computer. When I tried to deploy on another computer, the error I got was MSVCP120.dll is missing. To fix this I right-clicked on my project, clicked properties, then Configuration Properties > C/C++ > Code Generation, and I changed the Runtime Library from Multi-threaded DLL (/MD) to Multi-threaded (/MT). Now my program won't compile properly because of this build error:
Error 1 error LNK1104: cannot open file
'libboost_filesystem-vc120-mt-s-1_55.lib' C:\Users\inspection\Desktop\sortFile\Project1\Project1\LINK Project1
I looked in the following folder:
C:\Program Files\boost\boost_1_55_0\libs\filesystem\build\msvc-12.0\release\link-static\threading-multi
and I could not find libboost_filesystem-vc120-mt-s-1_55.lib, though I could find libboost_filesystem-vc120-mt-1_55.lib. The file names are close, they only differ by an '-s' term located after the '-mt' term.
How can I statically link the boost filesystem library so that my whole program runs as a standalone executable, without another user having to install anything?
Boost needs to be recompiled to match your new runtime library setting. The filename of the Boost library indicates the settings it was linked with, and the Boost auto-link code automatically updated the needed filename to match your new settings. In this case, it quite accurately indicates that you need a Boost lib which was compiled with a static stdlib link.

How to link opencv and other dll files to output exe of visual studio 2013

I am new with visual studio, opencv.
I am using visual studio 2013, opencv and c++ for my project.
I configured (copied path) the opencv and other library to my computer environment system.
After run the project in visual studio, normally, there will be an exe file in the project.
I can copy the exe file in the project folder and copy to other place in my computer and it will run normally.
This is because my computer environment systems are configured with opencv and other library.
I want to do the same thing with other computers BUT I do not want to manually configure each computer with opencv and other libraries.
Are there any ways that I can do to link everythings all in exe file after run the project in visual studio 2013 so that I can run the exe without depend on the path of libaries and opencv?
EDITED
I use opencv installer opencv2.4.7.exe
In the current VS2013 my project, i configured my project and opencv installer as this link
http://www.anlak.com/using-opencv-2-4-x-with-visual-studio-2010-tutorial/
question : Can i use the library in folder C:\opencv\build\x64\vc11\staticlib come from the opencv installer no need create my own library from source opencv?
question : In case i need to generate new library from opencv source (http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html) or use lib in static folder of opencv installer, if i want to include it all to exe files, do i need to create new project and reconfigure?
Thank you.
First you need to rebuild openCV to generate static libraries instead of dynamically linked ones. This way all code that your application uses is thrown together in one single exe-file (which will probably be significantly bigger). This exe-file you can move to other computers and they should still work there, provided they have an architecture that is at least compatible with yours. So if you build it on an x86 perconal computer (32-bit), it should basically work on any other personal computer. If you build it on a x64 computer (AMD 64-bit), it will only run on other x64 machines. At least this is true assuming both systems use the same syscall API (Windows NT, POSIX...).
For openCV you do this by setting the BUILD_SHARED_LIBS build flag to false (see OpenCV as a static library (cmake options), the following line is taken from there):
cmake -DBUILD_SHARED_LIBS=OFF ..
Once you have done this, you will see that the openCV folder looks very similar to the one you have now, except that in your 'lib' folder there will now be .lib-files instead of .dll files (at least if you are working on Windows, which I assume you do since you are using Visual Studio).
Next step is to go to your project settings and set your linker to link with the static libraries instead of the dynamically ones. If you have used openCV's local method for linking, you can go to project settings -> linker -> input -> Addtional dependencies. There you change the extension of all the openCV libraries from .dll to .lib.
Now you should be able to rebuild your application and the resulting exe-file should have all dependent libraries contained in it.

Application error - debug exe wont run

I've recently downloaded Assimp and I've run into some troubles.
I've linked the libraries and I can get the program to compile and it runs fine in Release mode; however, the Debug .exe hits me with this error:
The application was unable to start correctly (0xc0150002). Click OK to close the application.
Some more details:
I'm using VS2010 with Target Machine set to x86.
I am using the 32bit debug dll (Assimp32d.dll) that was provided, and I've tried setting runtime libraries to /MT, /MTd, /MD, and /MDd with no luck.
I read from other similar threads that I should run Dependency Walker on the .exe, but I'm not sure what the output means. I'll paste it here if this helps you guys.
Error: The Side-by-Side configuration information for "c:\users\-----\documents\visual studio 2010\projects\AssimpTest\debug\ASSIMP32D.DLL" contains errors. The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail (14001).
Error: At least one required implicit or forwarded dependency was not found.
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: Modules with different CPU types were found.
Rather than rebuilding the libraries, I downloaded a different set of libraries (it was the SDK installer) and the debug dll's from that are working perfectly.
Just in case anyone has the same problem with the same software, this was the exact name of the installer that worked for me: assimp-sdk-3.0-setup.exe
I ran into the same problem when trying to run a 64-bit project in Debug mode when using Assimp 3.0.
What I did was go to assimp/workspaces/vc9, open assimp.sln in Visual Studio 10, convert the project, then rebuild the 32 and 64-bit dll.
Mind you, you've got to install boost for that as well, and edit the project properties so it points to the boost directory for includes.
There's probably a way to do it using CMake as well, but I found the whole process too cumbersome to bother with in the first place.
My solution was just to link the debug build to the release .dll files. No more issues, and I wasn't that interested in debugging the Assimp library anyway!
I faced the same issue, later on I downloaded the "assimp-sdk-3.0-setup.exe" file & installed it as a standard windows application.
I pointed Visual Studio Solution Include & Lib directories to respective folders from newly installed location, copied DLL to my application location. The problem was resolved. Hope this helps someone.
Cheers.