简体   繁体   中英

Visual Studio - C++ - build and run app as 32bit or 64bit - load DLL from appropripate ProgramFiles dir

I build my app either as x86 or x64. This app uses external DLL.

I have x64 system (Windows 10) with the same DLL library installed for both platforms - x86 and x64. They are placed in same folders inside appropriate Program Files directory. I can manually set path to either one in environment variable PATH and it woks. But it is a little incovinient to rewrite PATH and reset computer when I switch platform and want to test the other one. Is there any solution, how system automatically loads correct DLL from correct Program Files dir?

Copy the DLL in the build location next to the executable, for Visual Studio this is typically \\Debug or \\Release in a architecture dependent sub directory (ie x86 or x64). Just make sure the target / output locations are set correctly in the project settings.

You have to copy only once, or more correctly: each time after you 'clean' the solution. To make this easier, many people use a dll-copy script (use batch, ruby or python) and have it run automatically before building or after cleaning. You can execute the script in a pre-build step or post-build step that can be configured in your Visual Studio solution or project settings.

There is also a more robust way to handle build artifacts and peculiarities: I highly recommend the use of CMake to keep the build matrix organized. It is provides a general cross-platform approach to script pre-build and post-build actions such as tracking dependencies, copying files, packaging installers, deployment, version verification, versioning, etc.. it comes with an easy scripting language so you can build macro's and functions to do your copying. It can be a bit of a learning curve to get it right, but once it's there, it provides a robust dependable way to build out your project build pipeline.

I have found solution for running apps from Visual Studio: How do I set the path to a DLL file in Visual Studio?

It is working as epxected. If I run app outise Visual Studio, I set PATH variable by myself and is also working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM