Summary
I am trying to compile ánd run/debug Qt code in Clion on Windows. Both CMake and the building process return no errors.
The following scenarios occur:
When I try to run I get
Process finished with exit code -1073741511 (0xC0000139)
When I try to debug I get
Process finished with exit code 1
When I try to run the executable via Windows CMD directly, the executable runs as intended.
When I copy all dll files from
../Qt/5.12.6/mingw73_64/bin
to the project'scmake-build-debug
folder, the executable runs and debugs within CLion as expected.
My setup
- Windows 10
- Qt 5.12.6 (mingw73_64 build)
- CLion 2019.2.5
- MinGW (x86_64-8.1.0-win32-seh-rt_v6_rev0)
- CMake (bundled, 3.15.3)
Other findings
I believe there are many related topics on StackOverflow that deal with the same issue. But none manage to provide a definitive answer to what I believe to be a Path/Environment issue. Many suggestions boil down to "Add Qt to your path/PATH/Path environment variable and reboot reboot reboot!", and/or mostly pertain to linux installs. Hence I hope this becomes a more complete question and answer for people running into the same error code within this context, as it is likely related to this same issue.
As things work outside of CLion (as shown by (3)) and work inside of CLion when I copy DLLs (4), I believe I am dealing a dynamic linking issue as a result of CLion related environment issues. Adding the Qt bin folder, which is C:\Qt\5.12.6\mingw73_64\bin
, to my System Environment Variables
made it so I could run the exe file directly from CMD. Note that I added the Qt bin folder path to the Path
variable.
Given that some mentioned online that it is possibly an issue with the user variables due to CLion running as a certain system user, I also added said path as a User Environment Variable
, again Path
. But alas.
Additionally, I tried adding it as an environment variable directly in CLion via Settings -> Appearance & Behavior -> Path Variables
. Here I tried mapping the Qt bin folder to Path
, PATH
, and QT_DIR
respectively. Still no success, even though I tried many reboots. Both Windows restarts and real shutdowns were attempted many times in between changing paths etc.
Main question:
How can I resolve the issue I described, so I can run and debug my Qt builds in CLion without having to copy Qt related DLLs to my cmake-build-debug
where the executable is located.
CMakeLists.txt
Within Settings -> Build, Execution, Deployment -> CMake
I have set CMake options:
to -DCMAKE_PREFIX_PATH=C:\\Qt\\5.12.6\\mingw73_64\\lib\\cmake
cmake_minimum_required(VERSION 3.8)
project(HelloWorld)
set(CMAKE_CXX_STANDARD 14)
# Include a library search using find_package()
# via REQUIRED, specify that libraries are required
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
set(SOURCE_FILES main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
# specify which libraries to connect
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Gui)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
main.cpp
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
int main (int argc, char * argv []) {
QApplication app (argc, argv);
QWidget widget;
widget.resize (640, 480);
widget.setWindowTitle ("Hello, world !!!");
QGridLayout * gridLayout = new QGridLayout (& widget);
QLabel * label = new QLabel ("Hello, world !!!");
label-> setAlignment (Qt :: AlignVCenter | Qt :: AlignHCenter);
gridLayout-> addWidget (label);
widget.show ();
return app.exec ();
}