c++qtvisual-studio-code

How to tell VS Code where is Qt dlls to use when launching my app


I'm using VS Code with "C/C++", "CMake Tools" and "Qt Official" extensions to build a simple console Qt app. The main.cpp is just printing "Hello, world" message. After building, console (with name "CMake/Launch") shows that it launching my app:

PS C:\Sumbur\QtExample\build\Debug> ."C:/Sumbur/QtExample/build/Debug/myApp.exe"

Which doesn't output anything and shows no errors. I've found that my app is just can't find Qt's DLLs - after executing windeployqt which copies all needed libraries, the app works properly and VS Code shows output.

How to tell VS Code to accompany my app with DLLs how, for example, Qt Creator does, without copying these DLLs to the build folder?


Solution

  • Thanks to Alan Birtles. The PATH environment should be added to launch config:

    "configurations": [
        {
            "name": "My application",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${command:cmake.getLaunchTargetDirectory}",
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [
                    {
                        // add the directory where our target was built to the PATHs
                        // it gets resolved by CMake Tools:
                        "name": "PATH",
                        "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}"
                    }
                ],
            "externalConsole": false
          }
        ]
    

    I don't understand why some people answer in comments instead of posting answers, so I did it myself just to close the topic.

    Update: Here is my CMakeLists.txt:

    cmake_minimum_required(VERSION 3.17)
    project(MyFirstQt)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_CXX_STANDARD 20)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    set(Qt6_DIR "C:/Dev/Qt/6.8.0/msvc2022_64/lib/cmake/Qt6")
    find_package(Qt6 REQUIRED COMPONENTS Core)
    qt_standard_project_setup()
    
    set(PROJECT_SOURCES
        ../src/main.cpp
    )
    
    qt_add_executable(myApp MANUAL_FINALIZATION ${PROJECT_SOURCES})
    
    target_link_libraries(myApp PRIVATE
        Qt6::Core
    )
    
    include(GNUInstallDirs)
    install(TARGETS myApp
        BUNDLE DESTINATION .
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    )
    
    qt_finalize_executable(myApp)
    

    Qt's bin folder aslo is in PATH var, but I didn't replaced hard-coded path to in yet.