我正在尝试使用
Qt
来设计我的应用程序(它将利用我的库),但我从 Qt
收到错误。我首先通过 Qt
安装 msys2
,如下所示:
pacman -S mingw-w64-ucrt-x86_64-qt6
然后我创建了一个
CMakeLists.txt
,如下所示:
cmake_minimum_required(VERSION 3.16)
project(test VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY bin)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_SYSTEM_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:\\msys64\\ucrt64\\include")
set(CMAKE_SYSTEM_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:\\msys64\\ucrt64\\lib")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 REQUIRED COMPONENTS Widgets)
qt_standard_project_setup()
qt_add_executable(
app
app/main.cpp
)
target_link_libraries(
app
PRIVATE
Qt6::Widgets
)
set_target_properties(app PROPERTIES
WIN32_EXECUTABLE ON
)
然后创建
app/main.cpp
文件:
#include <QApplication>
int main(int argc, char **argv) {
QApplication app(argc, argv);
return app.exec();
}
但是,当我构建代码时,出现以下错误:
[build] In file included from C:/msys64/ucrt64/include/qt6/QtCore/qnumeric.h:15,
[build] from C:/msys64/ucrt64/include/qt6/QtCore/qglobal.h:62,
[build] from C:/msys64/ucrt64/include/qt6/QtGui/qtguiglobal.h:7,
[build] from C:/msys64/ucrt64/include/qt6/QtWidgets/qtwidgetsglobal.h:7,
[build] from C:/msys64/ucrt64/include/qt6/QtWidgets/qapplication.h:7,
[build] from C:/msys64/ucrt64/include/qt6/QtWidgets/QApplication:1,
[build] from C:\Users\untun\Documents\vscode\draw\draw\app\main.cpp:1:
[build] C:/msys64/ucrt64/include/c++/13.2.0/cmath:47:15: fatal error: math.h: No such file or directory
[build] 47 | #include_next <math.h>
[build] | ^~~~~~~~
关于我为什么会收到此错误有什么想法吗?我是不是没有安装所有东西?
我现在也尝试使用 GTK 和 git 出现相同的错误,但包含不同的内容:
pacman -S mingw-w64-ucrt-x86_64-gtk4
使用这个cmake:
cmake_minimum_required(VERSION 3.16)
project(draw VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY bin)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK4 REQUIRED IMPORTED_TARGET gtk4)
add_executable(app main.cpp)
target_link_libraries(
app
PRIVATE
PkgConfig::GTK4
)
还有这个cpp文件:
#include <gtk/gtk.h>
using namespace std;
static void activate(GtkApplication *app) {
GtkWidget *window = gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW(window), "Window");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
}
int main(int argc, char *argv[]) {
GtkApplication *app = gtk_application_new("com.example.GtkApplication",
G_APPLICATION_FLAGS_NONE);
return g_application_run(G_APPLICATION(app), argc, argv);
}
导致此错误:
[build] In file included from C:/msys64/ucrt64/include/c++/13.2.0/ext/string_conversions.h:43,
[build] from C:/msys64/ucrt64/include/c++/13.2.0/bits/basic_string.h:4097,
[build] from C:/msys64/ucrt64/include/c++/13.2.0/string:54,
[build] from C:/msys64/ucrt64/include/c++/13.2.0/bits/locale_classes.h:40,
[build] from C:/msys64/ucrt64/include/c++/13.2.0/bits/ios_base.h:41,
[build] from C:/msys64/ucrt64/include/c++/13.2.0/ios:44,
[build] from C:/msys64/ucrt64/include/c++/13.2.0/ostream:40,
[build] from C:/msys64/ucrt64/include/c++/13.2.0/iostream:41,
[build] from C:\Users\untun\Documents\vscode\draw\draw\src\app\main.cpp:3:
[build] C:/msys64/ucrt64/include/c++/13.2.0/cstdlib:79:15: fatal error: stdlib.h: No such file or directory
[build] 79 | #include_next <stdlib.h>
[build] | ^~~~~~~~~~
我可以通过将以下内容添加到我的
CMakeLists.txt
文件中来解决此问题:
include_directories(
BEFORE
SYSTEM
"C:\\msys64\\ucrt64\\include\\c++\\13.2.0"
)