gpt4 book ai didi

c++ - 无法使用 cmake 使 QPrinter 链接

转载 作者:可可西里 更新时间:2023-11-01 13:51:26 25 4
gpt4 key购买 nike

所以我一直在尝试让我的程序与 QPrinter 一起使用 cmake+mingw+qt5.2 进行编译,但我遇到了问题:以下测试程序无法编译,因为它找不到应该是一部分的 QPrinter QtCore的

#include <QPrinter>
#include <QApplication>
#include <windows.h>

int main()
{
QApplication a( argc, argv );

return 0;
} // end

这是我的cmake文件

    SET(CMAKE_C_COMPILER E:/Qt/Qt5.2.1/Tools/mingw48_32/bin/gcc.exe)
SET(CMAKE_CXX_COMPILER E:/Qt/Qt5.2.1/Tools/mingw48_32/bin/g++.exe)
cmake_minimum_required(VERSION 2.8)

PROJECT (test_prog)
add_definitions(-std=c++11)
SET( test_prog_SRCS test.cpp)
# Tell CMake to run moc when necessary:
set(CMAKE_AUTOMOC ON)
# As moc files are generated in the binary dir, tell CMake
# to always look for includes there:
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Widgets finds its own dependencies.
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)

include_directories(
${Qt5Widgets_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Core_INCLUDE_DIRS}
)

add_executable(test_prog WIN32 ${test_prog_SRCS})
target_link_libraries(test_prog ${Qt5Widgets_LIBRARIES} ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} )

错误是:

test.cpp:1:20: fatal error: QPrinter: No such file or directory
#include <QPrinter>

有谁知道正确的咒语来让它工作?

最佳答案

使用 CMake 2.8.11:

SET(CMAKE_C_COMPILER E:/Qt/Qt5.2.1/Tools/mingw48_32/bin/gcc.exe)
SET(CMAKE_CXX_COMPILER E:/Qt/Qt5.2.1/Tools/mingw48_32/bin/g++.exe)
cmake_minimum_required(VERSION 2.8.11)

PROJECT (test_prog)
add_definitions(-std=c++11)
SET( test_prog_SRCS test.cpp)
# Tell CMake to run moc when necessary:
set(CMAKE_AUTOMOC ON)
# As moc files are generated in the binary dir, tell CMake
# to always look for includes there:
set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(Qt5PrintSupport REQUIRED)

add_executable(test_prog WIN32 ${test_prog_SRCS})
target_link_libraries(test_prog Qt5::PrintSupport)

关于c++ - 无法使用 cmake 使 QPrinter 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22079279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com