I was looking up how to compile QT dynamically linked projects in cmake with clion IDE. I've run into issues with the following project set up. I've followed this tutorial, compiled, and ran it with mingw32 bit and a kit with that links to Qt compiled with mingw-w64 (whose qmake file is found in C:/msys64/mingw64/bin)
My project setup looks like this:
CMakeLists.txt
main.cpp
notepad.cpp
notepad.h
notepad.ui
In clion, I've used the follwing cmake file in order to build this project.
cmake_minimum_required(VERSION 3.7)
set(CMAKE_PREFIX_PATH C:/msys64/mingw64/bin)
project(qttest)
set(QT_ROOT_DIR "C:/msys64/mingw64/bin")
set(QT_QMAKE_EXECUTABLE ${QT_ROOT_DIR}/qmake)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui)
add_library(notepad notepad.cpp)
target_link_libraries (notepad Qt5::Core Qt5::Widgets Qt5::Gui)
set(SOURCE_FILES main.cpp)
add_executable(qttest ${SOURCE_FILES})
target_link_libraries(qttest notepad)
After getting the following errors on build:
{projectdir}/qttest/main.cpp:6: undefined reference to `__imp__ZN12QApplicationC1ERiPPci'
... (1000 of these types of errors) ...
CMakeFiles\qttest.dir\build.make:127: recipe for target 'qttest.exe' failed
CMakeFiles\Makefile2:104: recipe for target 'CMakeFiles/qttest.dir/all' failed
mingw32-make.exe[3]: *** [qttest.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/qttest.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/qttest.dir/rule] Error 2
CMakeFiles\Makefile2:116: recipe for target 'CMakeFiles/qttest.dir/rule' failed
Makefile:130: recipe for target 'qttest' failed
mingw32-make.exe: *** [qttest] Error 2
I googled for a solution, and it appears that it was linking to the 32bit mingw installation of QT. This would make sense since I'm compiling with mingw-w64, so I look for a solution here(to include qt via findpackages) to solve this issue. This doesn't really work, so I go to find another solution here, which also happens to not work (setting enviroment variable to qmake directory). This one also failed do do anything (appending path variable specifically to C:/msys64/mingw64/bin).
Not sure what the issue is, but any help would be appreciated.
EDIT: Current sitatuation, I feel like I've tried everything, but I foudn that when doing the following:
get_target_property(QtCore_location Qt5::Core LOCATION)
message("qtcore location ${QtCore_location}")
the cmake output is actually
qtcore location C:/ProgramData/Anaconda3/Library/bin/Qt5Core.dll
So clearly its linking to my anaconda installation, but why how do I stop it!!! It doesn't seem to want to use anything else, Anaconda appears in path but I need to keep it there.