Visual Studio 2022 CMake project
I build a qt cmake project in vs2022, everything works well, but when last step to run exe, it says the error of lack of dll files. I know that this is the problem of dll file directory. I can add it to system env path, or copy dll to exe file dir, but I guess that additional way that not mucks system env exists. I notice that VS traditional project can set debugger env in property, which set a local env variable, but I cannot find the way to set this in new support CMake Project in VS2022.
The IDE QtCreator also provide an analogous way that set env var for only project to run exe file, so any way to set this in VS like the traditional sln project, I search and find that some configure json file may help, but I cann't find precise setting.
As above, I guess some ways exist to set exe runtime env var to find dll file in VS CMake project, anyone could give me any tip, any helpful advice would be highly appreciated!
CodePudding user response:
You can add the following properties to your CMakeLists.txt
file that contains the executable target:
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT <your_executable_target_name>)
set_property(TARGET <your_executable_target_name> PROPERTY VS_DEBUGGER_ENVIRONMENT "PATH=${QTDIR}/bin")
CodePudding user response:
Finally, I find the way for cmake project without solutions in visual studio, find launch.vs.json
file by this, add custom env variable path to json file, add following content to project in configurations
key:
"env": {
"PATH": "<dll-file-path>"
}
It works well for me, hope this can help you.