我使用本教程为Windows设置了QT-https://wiki.qt.io/MinGW-64-bit
我需要使用CMAKE
我在qtcreator中创建了一个空项目,但是当我尝试进行cmake时,出现此错误:
Starting to parse CMake project, using: "-DCMAKE_BUILD_TYPE:STRING=Debug", "-DCMAKE_CXX_COMPILER:STRING=C:/msys64/mingw64/bin/g++.exe", "-DCMAKE_CXX_COMPILER_TARGET :STRING=x86_64-pc-msys", "-DCMAKE_C_COMPILER:STRING=C:/msys64/mingw64/bin/gcc.exe", "-DCMAKE_C_COMPILER_TARGET:STRING=x86_64-pc-msys", "-DCMAKE_PREFIX_PATH:STRING=C:/msys64/mingw64", "-DCMAKE_SYSROOT:STRING=C:/msys64", "-DQT_QMAKE_EXECUTABLE:STRING=C:/msys64/mingw64/bin/qmake.exe".
The CXX compiler identification is GNU 9.2.0
Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe
Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe -- broken
CMake Error at C:/msys64/mingw64/share/cmake-3.15/Modules/CMakeTestCXXCompiler.cmake:53 (message):
The C++ compiler
"C:/msys64/mingw64/bin/g++.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/xxx/AppData/Local/Temp/QtCreator-RwlXKb/qtc-cmake-tQFVtoZK/CMakeFiles/CMakeTmp
Run Build Command(s):C:/msys64/usr/bin/ninja.exe cmTC_373cd && [1/2] Building CXX object CMakeFiles/cmTC_373cd.dir/testCXXCompiler.cxx.obj
FAILED: CMakeFiles/cmTC_373cd.dir/testCXXCompiler.cxx.obj
C:\msys64\mingw64\bin\g++.exe --sysroot=C:/msys64 -o CMakeFiles/cmTC_373cd.dir/testCXXCompiler.cxx.obj -c testCXXCompiler.cxx
/bin/sh: C:msys64mingw64bing++.exe: command not found
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
Configuring incomplete, errors occurred!
See also "C:/Users/xxx/AppData/Local/Temp/QtCreator-RwlXKb/qtc-cmake-tQFVtoZK/CMakeFiles/CMakeOutput.log".
See also "C:/Users/xxx/AppData/Local/Temp/QtCreator-RwlXKb/qtc-cmake-tQFVtoZK/CMakeFiles/CMakeError.log".
CMake Deprecation Warning:
The 'cmake-server(7)' is deprecated. Please port clients to use the
'cmake-file-api(7)' instead.
CMake Project parsing failed.
此字符串似乎有错误:
C:msys64mingw64bing++.exe
因为斜杠处理不正确。
那么我该如何解决?设置存储在哪里?
更新1
这是我的CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(t2 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Core Quick REQUIRED)
if(ANDROID)
add_library(t2 SHARED main.cpp qml.qrc)
else()
add_executable(t2 main.cpp qml.qrc)
endif()
target_compile_definitions(t2
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(t2
PRIVATE Qt5::Core Qt5::Quick)
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# These variables must use CACHE, otherwise QtCreator won't see them.
#if(ANDROID)
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android" CACHE INTERNAL "")
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
# set(ANDROID_EXTRA_LIBS ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so CACHE INTERNAL "")
# endif()
#endif()
我尝试启动cmake CMakeLists.txt
,它创建了makefile
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.15
# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target
# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake.exe
# The command to remove a file.
RM = /usr/bin/cmake.exe -E remove -f
# Escaping for special characters.
EQUALS = =
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /c/projects/t2
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /c/projects/t2
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake.exe -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
/usr/bin/ccmake.exe -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /c/projects/t2/CMakeFiles /c/projects/t2/CMakeFiles/progress.marks
$(MAKE) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /c/projects/t2/CMakeFiles 0
.PHONY : all
# The main clean target
clean:
$(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast
# clear depends
depend:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
#=============================================================================
# Target rules for targets named t2
# Build rule for target.
t2: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 t2
.PHONY : t2
# fast build rule for target.
t2/fast:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/build
.PHONY : t2/fast
#=============================================================================
# Target rules for targets named t2_autogen
# Build rule for target.
t2_autogen: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 t2_autogen
.PHONY : t2_autogen
# fast build rule for target.
t2_autogen/fast:
$(MAKE) -f CMakeFiles/t2_autogen.dir/build.make CMakeFiles/t2_autogen.dir/build
.PHONY : t2_autogen/fast
main.o: main.cpp.o
.PHONY : main.o
# target to build an object file
main.cpp.o:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/main.cpp.o
.PHONY : main.cpp.o
main.i: main.cpp.i
.PHONY : main.i
# target to preprocess a source file
main.cpp.i:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/main.cpp.i
.PHONY : main.cpp.i
main.s: main.cpp.s
.PHONY : main.s
# target to generate assembly for a file
main.cpp.s:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/main.cpp.s
.PHONY : main.cpp.s
t2_autogen/EWIEGA46WW/qrc_qml.o: t2_autogen/EWIEGA46WW/qrc_qml.cpp.o
.PHONY : t2_autogen/EWIEGA46WW/qrc_qml.o
# target to build an object file
t2_autogen/EWIEGA46WW/qrc_qml.cpp.o:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/t2_autogen/EWIEGA46WW/qrc_qml.cpp.o
.PHONY : t2_autogen/EWIEGA46WW/qrc_qml.cpp.o
t2_autogen/EWIEGA46WW/qrc_qml.i: t2_autogen/EWIEGA46WW/qrc_qml.cpp.i
.PHONY : t2_autogen/EWIEGA46WW/qrc_qml.i
# target to preprocess a source file
t2_autogen/EWIEGA46WW/qrc_qml.cpp.i:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/t2_autogen/EWIEGA46WW/qrc_qml.cpp.i
.PHONY : t2_autogen/EWIEGA46WW/qrc_qml.cpp.i
t2_autogen/EWIEGA46WW/qrc_qml.s: t2_autogen/EWIEGA46WW/qrc_qml.cpp.s
.PHONY : t2_autogen/EWIEGA46WW/qrc_qml.s
# target to generate assembly for a file
t2_autogen/EWIEGA46WW/qrc_qml.cpp.s:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/t2_autogen/EWIEGA46WW/qrc_qml.cpp.s
.PHONY : t2_autogen/EWIEGA46WW/qrc_qml.cpp.s
t2_autogen/mocs_compilation.o: t2_autogen/mocs_compilation.cpp.o
.PHONY : t2_autogen/mocs_compilation.o
# target to build an object file
t2_autogen/mocs_compilation.cpp.o:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/t2_autogen/mocs_compilation.cpp.o
.PHONY : t2_autogen/mocs_compilation.cpp.o
t2_autogen/mocs_compilation.i: t2_autogen/mocs_compilation.cpp.i
.PHONY : t2_autogen/mocs_compilation.i
# target to preprocess a source file
t2_autogen/mocs_compilation.cpp.i:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/t2_autogen/mocs_compilation.cpp.i
.PHONY : t2_autogen/mocs_compilation.cpp.i
t2_autogen/mocs_compilation.s: t2_autogen/mocs_compilation.cpp.s
.PHONY : t2_autogen/mocs_compilation.s
# target to generate assembly for a file
t2_autogen/mocs_compilation.cpp.s:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/t2_autogen/mocs_compilation.cpp.s
.PHONY : t2_autogen/mocs_compilation.cpp.s
# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... rebuild_cache"
@echo "... t2"
@echo "... edit_cache"
@echo "... t2_autogen"
@echo "... main.o"
@echo "... main.i"
@echo "... main.s"
@echo "... t2_autogen/EWIEGA46WW/qrc_qml.o"
@echo "... t2_autogen/EWIEGA46WW/qrc_qml.i"
@echo "... t2_autogen/EWIEGA46WW/qrc_qml.s"
@echo "... t2_autogen/mocs_compilation.o"
@echo "... t2_autogen/mocs_compilation.i"
@echo "... t2_autogen/mocs_compilation.s"
.PHONY : help
#=============================================================================
# Special targets to cleanup operation of make.
# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system
当我尝试使用make
构建它时,我得到了
C:\projects\t2>make
[ 16%] Automatic MOC and UIC for target t2
[ 16%] Built target t2_autogen
[ 33%] Automatic RCC for qml.qrc
Scanning dependencies of target t2
[ 50%] Building CXX object CMakeFiles/t2.dir/t2_autogen/mocs_compilation.cpp.o
[ 66%] Building CXX object CMakeFiles/t2.dir/main.cpp.o
[ 83%] Building CXX object CMakeFiles/t2.dir/t2_autogen/EWIEGA46WW/qrc_qml.cpp.o
[100%] Linking CXX executable t2.exe
CMakeFiles/t2.dir/main.cpp.o:main.cpp:
(.text$_ZN15QTypedArrayDataItE10deallocateEP10QArrayData[_ZN15QTypedArrayDataItE10deallocateEP10QArrayData]+0x1c): undefined reference to `QArrayData::deallocate(QArrayData*, unsigned long, unsigned long)'
CMakeFiles/t2.dir/main.cpp.o:main.cpp:(.text$_ZN15QTypedArrayDataItE10deallocateEP10QArrayData[_ZN15QTypedArrayDataItE10deallocateEP10QArrayData]+0x1c): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `QArrayData::deallocate(QArrayData*, unsigned long, unsigned long)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/t2.dir/build.make:126: t2.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:77: CMakeFiles/t2.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
这里是程序的源代码:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
答案 0 :(得分:0)
好吧,我已修复它,看来忍者工具会导致Windows下的所有问题!
我从我的简单项目中删除了所有文件,因此它仅包含以下文件:
CMakeLists.txt
Makefile
main.cpp
main.qml
qml.qrc
在Qtcreator中,我转到工具->选项->套件
CMake生成器-> MSYS Makefile
在Cmake工具中,选择路径为C:\msys64\mingw64\bin\cmake.exe
,或者您可能需要手动添加
在我按“确定”并退出选项后,所有功能都可以正常工作。 CMAKE配置项目并对其进行编译并运行。