how to tell VS to copy native dll to "final destination folder" - build

In my project I have
native c++ dll project (output to x64/)
c++/cli wrapper (output to x64/)
several c# projects (output to projectName\bin\x64)
While building first dll is copied to "x64/"
Then wrapper is copied to "x64/". At final stage wrappper dll is copied to "projectName\bin\x64" folder, but original native dll didn't copied.
I need native dll also go to the final folder, so I can run application, how to do that?
I have tried to add "native dll" as a dependency, but VS says that it is not possible.
upd Also if I copy dll myself and then debug I can't go into native dll, I receive "The breakpoint will not currently be hit. No symbols have been loaded for this document" error. So I assume this problems are connected. I want native dll to be copied and I want to be able to debug.
upd This answer helped me to debug Cannot Debug Unmanaged Dll from C# however I still have to copy dll myself. What is odd because every time I build project I have a warning that "native dll" project is out of date.

As far as I can tell, you'll need to use a post-build step. Here are a couple of examples:
How do I exclude a specific file from my msbuild AfterBuild target
<Target Name="AfterBuild">
<ItemGroup>
<BinFiles Include="bin\$(ConfigurationName)\**\*.*" />
</ItemGroup>
<Copy SourceFiles="#(BinFiles)" DestinationFiles="#(BinFiles->'$(ProjectDir)\relativePathToDirectory" />
</Target>

Related

Reference a native dll so it appears in a subfolder of the UWP project

I'm on a C# UWP gui app, which references a C++ UWP project, which itself uses native dlls (opengl and some others) without referencing them explicitly.
All is working correctly.
But it works only when i add the native dlls to the C# UWP project, and only at the root of the project. Which makes it very messy as there are about 40 dlls.
If i move these dlls in a subfolder of the project, as soon as a C# calls C++, it crashes with a message 'dll or one of its ref ... not found'.
I've already tried that https://social.msdn.microsoft.com/Forums/windowsapps/en-US/26013e5e-3ff1-44a0-8797-0474dabd12d0/uwpincluding-dlls-in-a-uwp-application-in-visual-studio?forum=wpdevelop
Any solution other than creating a post build event or custom msbuild code that copies dlls from the subfolder into the output root folder ?
The reference in the csproj file looks like this:
<Content Include="..\..\..\..\..\..\..\opencv\bin\opencv_features2d411d.pdb" Condition="'$(Configuration)'=='Debug'">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>opencv_features2d411d.pdb</Link>
</Content>

Build process hangs when recursively building solution

While trying to answer this SO question I encountered an issue which I cannot explain and would appreciate your input on.
Setup:
Have solution consisting of several C++ projects (Test.sln),
Add a brand new project to your solution (BuildInstaller.vcxproj),
Open BuildInstaller.vcxproj in text editor and append following xml fragment right before closing </Project> tag:
<Target Name="Build">
<MSBuild Projects="..\Test.sln" Properties="Configuration=Release;Platform=Win32" />
<MSBuild Projects="..\Test.sln" Properties="Configuration=Release;Platform=x64" />
</Target>
Above code overrides default Build target of the BuildInstaller project and everytime the project is being built, it builds its parent solution with Release configuration for both Win32 and x64 platforms,
To prevent unbounded recursion, open Configuration Manager in Visual Studio and uncheck "Build" checkbox for BuildInstaller project for all combinations of Debug/Release and Win32/x64,
Then, still in Configuration Manager, create a new configuration, e.g. Installer for which you should uncheck all the other project's Build checkbox and leave it checked for BuildInstaller only,
Now build your solution for Installer configuration.
I would expect this build to finish successfully, but it simply hangs, even though BuildInstaller should not be built recursively as we are recursively building the Test.sln only for Release configuration.
I am not asking whether this is a good approach or how to work around it, I am just curious why the build hangs. Setting output window verbosity to Diagnostic was of no help to me.
I am using Visual Studio 2013 Ultimate.
MSBuild has an internal protection about recursion in the projects. Normally your build will fail with error MSB4006 in a case if any sort of circular dependency is discovered in the build graph. That said, if I were to guess what might have caused the hang, and if it is related to recursion, I would have inclined on the side of .sln files. The reason is that the way MSBuild treats .sln files is quite peculiar. Any time it encounters .sln file, it converts it to intermediate representation that actual MSBuild engine can understand. That intermediate representation does not have any identifier similar to the project file, thus the circular dependency detection logic might not work correctly if .sln is in the loop.
To solve your particular problem, there are couple of ways. The easiest one is to remove BuildInstaller.vcxproj from Test.sln. The second is to modify BuildInstaller.vcxproj as follows:
First, create an ItemGroup, populated with all projects from the solution:
<ItemGroup>
<AllMyProjects Include="..\Proj1\Proj1.vcxproj" />
<AllMyProjects Include="..\Proj2\Proj2.vcxproj" />
...
<!-- DO NOT ADD BuildInstaller project to prevent recursion!!! -->
</ItemGroup>
Then build the projects for every configuration:
<Target Name="Build">
<MSBuild Projects="#AllMyProjects" Properties="Configuration=Release;Platform=Win32" />
<MSBuild Projects="#AllMyProjects" Properties="Configuration=Release;Platform=x64" />
</Target>
The downside of the second approach is that you have to remember to maintain list of projects in sync between .sln and your installer project.

CMake to add arbitrary file to Visual Studio project

I'm trying to reference extra files (in fact DLL) from my Visual Studio project generated from CMake.
If I add my files from the Visual Studio UI, the XML project file produces something like:
<None Include="C:\foo.dll" />
Then, this file is properly deployed when debugging my (C++) application on my Windows Phone.
I didn't find anything allowing me to do that directly from CMake.
My attempts so far were to use source_group combined with add_executable which produces the expected <None Include="C:\foo.dll" /> but produces a link error (obviously).
Nothing working using source_files_properties either.
My final goal is to deploy an executable relying on those DLL but not linking directly against them (so, CMake's target_link_libraries doesn't help me), only loading them at runtime using LoadPackagedLibrary.
Has anybody an idea to do so?
Use FILE(COPY ...) to copy the DLL into the correct directory in your build tree, if you run directly out of the build tree. Use INSTALL() to install the file along with everything else.

C++ - unable to start correctly (0xc0150002)

I'm trying to run an OpenCV application through Microsoft Visual C++ 2010 Express, and get the following message:
How can I solve this issue?
I agree with Brandrew, the problem is most likely caused by some missing dlls that can't be found neither on the system path nor in the folder where the executable is. Try putting the following DLLs nearby the executable:
the Visual Studio C++ runtime (in VS2008, they could be found at places like C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86.) Include all 3 of the DLL files as well as the manifest file.
the four OpenCV dlls (cv210.dll, cvaux210.dll, cxcore210.dll and highgui210.dll, or the ones your OpenCV version has)
if that still doesn't work, try the debug VS runtime (executables compiled for "Debug" use a different set of dlls, named something like msvcrt9d.dll, important part is the "d")
Alternatively, try loading the executable into Dependency Walker ( http://www.dependencywalker.com/ ), it should point out the missing dlls for you.
In my case, Visual Leak Detector I was using to track down memory leaks in Visual Studio 2015 was missing the Microsoft manifest file Microsoft.DTfW.DHL.manifest, see link Building Visual Leak Detector all way down. This file must be in the folder where vld.dll or vld_x64.dll is in your configuration, say C:\Program Files (x86)\Visual Leak Detector\bin\Win32, C:\Program Files (x86)\Visual Leak Detector\bin\Win64, Debug or x64/Debug.
I take it that is a Vista Window! I often got this when first trying to port a DirectX program from XPsp3 to Vista.
It's a .dll problem. The OpenCV runtime.dll will call upon a system.dll that will be no longer shipped Vista, so unfortunately you will have to to a bit of hunting to find which system.dll it's trying to find. (system.dll could be vc2010 or vista)
This error is also caused by incorrect installation of .dlls (i.e not rolling out)
hth
Happy hunting
I got this error when trying to run my friend's solution file by visual studio 2010 after convert it to 2010 version. The fix is easy, I create new project, right click the solution to add existing .cpp and .h file from my friend's project. Then it work.
Just run .exe file in dependency walker( http://dependencywalker.com/)
and it will point you the missing dlls and download those dll (www.dll-files.com) and paste in the c:windows:system32 and the folder as your .exe and even provide the path of those dll in path variable.
Even I faced same error, I fixed it afterwards...
Two things you need to look into
Whether your system path is correctly set in your environment variables
Check the pre-processors in Project Properties->c/c++->Pre-processors. Check whether you have included _CONSOLE, this was causing error for me. For Some applications you need to include WIN32;_WINDOWS;_CONSOLE;_DEBUG;QT_DLL;QT_GUI_LIB;QT_NETWORK_LIB;QT_CORE_LIB;COIN_DLL;SOQT_DLL;QT_DEBUG;
I got this error while I was working in coin3D Application.
I met such problem. Visual Studio 2008 clearly said: problem was caused by libtiff.dll. It cannot be loaded for some reasom, caused by its manifest (as a matter of fact, this dll has no manifest at all). I fixed it, when I had removed libtiff.dll from my project (but simultaneously I lost ability to open compressed TIFFs!). I recompiled aforementioned dll, but problem still remains. Interesting, that at my own machine I have no such error. Three others comps refused to load my prog. Attention!!! Here http://www.error-repair-tools.com/ppc/error.php?t=0xc0150002 one wise boy wrote, that this error was caused by problem with registry and offers repair tool. I have a solid guess, that this "repair tool" will install some malicious soft at your comp.
It is because there is a DLL that your program is missing or can't find.
In your case I believe you are missing the openCV dlls. You can find these under the "build" directory that comes with open CV. If you are using VS2010 and building to an x86 program you can locate your dlls here under "opencv\build\x86\vc10\bin". Simply copy all these files to your Debug and Release folders and it should resolve your issues.
Generally you can resolve this issue using the following procedure:
Download Dependency Walker from here: http://www.dependencywalker.com/
Load your .exe file into Dependency Walker (under your projects Debug or Release folder), in your case this would be DisplayImage.exe
Look for any DLL's that are missing, or are corrupt, or are for the wrong architecture (i.e. x64 instead of x86) these will be highlighted in red.
For each DLL that you are missing either copy to your Debug or Release folders with your .exe, or install the required software, or add the path to the DLLs to your environment variables (Win+Pause -> Advanced System Settings -> Environment Variables)
Remember that you will need to have these DLLs in the same directory as your .exe. If you copy the .exe from the Release folder to somewhere else then you will need those DLLs copied with the .exe as well. For portability I tend to try and have a test Virtual Machine with a clean install of Windows (no updates or programs installed), and I walk through the Dependencies using the Dependency Walker one by one until the program is running happily.
This is a common problem. Also see these questions:
Can't run a vc++, error code 0xc0150002
The application was unable to start (0xc0150002) with libcurl C++ Windows 7 VS 2010
0xc0150002 Error when trying to run VC++ libcurl
The application was unable to start correctly 0xc150002
The application was unable to start correctly (0*0150002) - OpenCv
Good Luck!
In our case (next to trying Dependency Walker) it was a faulty manifest file, mixing 64 bits and 32 bits. We use two extra files while running in Debug mode: dbghelp.dll and Microsoft.DTfW.DHL.manifest.
The manifest file looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- $Id -->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<noInheritable />
<assemblyIdentity type="win32" name="Microsoft.DTfW.DHL" version="6.11.1.404" processorArchitecture="x86" />
<file name="dbghelp.dll" />
</assembly>
Notice the 'processorArchitecture' field. It was set to "amd64" instead of "x86". It's probably not always the cause, but in our case it was the root cause, so it may be helpful to some. For 64-bit runs, you'll want "amd64" in there.
I faced this issue, when I was supplying the executable folder with a, by the .exe requested DLL.
In my case, the DLL I supplied to the .exe was searching for another necessary DLL which was not available.
The searching DLL was not capable of telling that it can not find the necessary DLL.
You might check the DLLs you're loading and the dependencies of these DLL's.
Here is my solution for this error:
(The Application was unable to start correctly (OXO15OOO20).Click to close the application).
From the Start menu, click Administrative Tools, and then click Windows Server Backup.
Click File, Click Option, and then in Disk Cleanup press Delete files and then press O.K,
and delete till it reaches to 0 byete
No Worry About it just it deletes the amount of disk space on your computer.

VC++ project never up-to-date

I'm using Visual Studio 2008.
I have a solution with two projects. One builds a DLL, which is my "production code". The other builds a console app exe, which is my unit test suite.
For my unit test project, I have listed as linker inputs the names of the source modules from the DLL. I.e., I have a DLLMain.cpp in the DLL project, and a linker input "DLLMain" in the exe project. This allows the exe to link with the obj files produced by the DLL project, preventing recompilation of those modules just for the unit tests. (Saves a lot of build time.)
THE PROBLEM IS that because the exe is produced later than the obj's, and by a different project, its timestamp is always newer than the obj's. So when you try to run or debug, it ALWAYS says the exe project is out of date and needs to be rebuilt.
Is there some way I can configure the exe project to ignore the timestamps? Or is there some other, perhaps more general, solution I'm not seeing here?
Seems like you are creating foo.obj in the DLL's project, linking foo.obj in the DLL project to produce the DLL, and then linking foo.obj to your EXE project without first recompiling it.
I have never done this before, but first thing I would check is to make sure the Intermediate Directory settings are the same for both the EXE project and the DLL project.
Go to the project that is not needed for unit testing
Right click on it and press Properties
Click on Configuration manager
Add a new configuration using the first drop down list
Click ok
Select that configuration in the window that is now focused
then in configuration properties set "Excluded From Build" to yes