How to set up the debugging environment in VisualStudio's CMake project to find the dll files needed for debugging

Sometimes some projects need to find dll files when they are running. For example, projects that use OpenCV as a third-party library need to find opencv_world450d.dll and other files when running. If you do not set them in the VS IDE, the most basic method is to copy opencv_world450d.dll Go to the directory where the executable file is located, but this method always feels not elegant enough, why not let the IDE find the dll file by itself?
In the VS self-built project, you can set the debugging environment in the project-properties, but the self-built CMake project in VS does not seem to have this entry.
At this time, it is enough to configure the PATH variable in the launch.vs.json file.
How to open the launch.vs.json file?
There are two methods, one is to open it as shown in the figure below,
insert image description here
and the other is to right-click and add debug configuration in the CMakeTargetview in the solution browser to get it.
insert image description here
insert image description here
insert image description here
Here I am VIPL-SLAM, and yours is your own executable file.
After opening launch.vs.json, add the env environment variable in the configurations
as follows:
insert image description here
The opencv_world450d.dll and realsense2.dll I need to use here are in these two folders. Click Debug again to succeed.

Guess you like

Origin blog.csdn.net/u013238941/article/details/125752851