gpt4 book ai didi

Ubuntu 13.04 CMake 和 Qt4 和 Qt5

转载 作者:太空宇宙 更新时间:2023-11-03 16:52:14 26 4
gpt4 key购买 nike

我正在使用新的 Ubuntu 13.04 并通过 apt-get install 安装了 qt。现在好像安装了qt5。使用 qt5 的 CMake 项目运行良好。

我在 ubuntu 12.04 上安装了 qt4 的机器上运行了相同的代码,并且运行良好。但是现在我得到以下错误:(不要担心提升的东西,它来自父 CMakeLists.txt)

CMake Error at /usr/share/cmake-2.8/Modules/FindQt4.cmake:619 (message):
Could NOT find QtCore. Check
/home/simongroth/Projects/pgCrazyMachinesVR/src-build2/CMakeFiles/CMakeError.log
for more details.
Call Stack (most recent call first):
Views/LevelEditor/CMakeLists.txt:32 (FIND_PACKAGE)


CMake Warning at /usr/share/cmake-2.8/Modules/FindQt4.cmake:615 (message):
/usr/bin/qmake-qt4 reported QT_INSTALL_LIBS as "/usr/lib/x86_64-linux-gnu"
but QtCore could not be found there. Qt is NOT installed correctly for the
target build environment.
Call Stack (most recent call first):
Views/LevelEditor/CMakeLists.txt:32 (FIND_PACKAGE)

-- Boost version: 1.49.0
-- Found the following Boost libraries:
-- thread
-- Configuring incomplete, errors occurred!

这是我的 CMakeLists.txt。有谁知道如何在新的 ubuntu 上同时使用 qt4 和 qt5?提前致谢。

FILE(GLOB COLLECTED_HDR_FILES *.hpp)
FILE(GLOB COLLECTED_SRC_FILES *.cpp)
FILE(GLOB COLLECTED_UI_FILES *.ui)
FILE(GLOB COLLECTED_RCS_FILES *.qrc)

SET( SRCS
${COLLECTED_SRC_FILES}
)

SET( HDRS
${COLLECTED_HDR_FILES}
)

SET( MOC_HDRS
${HDRS}
)

SET( UIS
${COLLECTED_UI_FILES}
)

SET( RCS
${COLLECTED_UI_FILES}
MainWindow.qrc
)

# enable warnings
ADD_DEFINITIONS(-Wall)

# this command finds Qt4 libraries and sets all required variables
# note that it's Qt4, not QT4 or qt4
FIND_PACKAGE(Qt4 REQUIRED)
FIND_PACKAGE(OpenGL REQUIRED)

# by default only QtCore and QtGui modules are enabled
# other modules must be enabled like this:
SET(QT_USE_QTXML TRUE)
SET(QT_USE_QTOPENGL TRUE)

# add some useful macros and variables
# (QT_USE_FILE is a variable defined by FIND_PACKAGE( Qt4 ) that contains a path to CMake script)
INCLUDE( ${QT_USE_FILE} )

# this command will generate rules that will run rcc on all files from SAMPLE_RCS
# in result SAMPLE_RC_SRCS variable will contain paths to files produced by rcc
QT4_ADD_RESOURCES( RC_SRCS ${RCS} )

# this will run uic on .ui files:
QT4_WRAP_UI( UI_HDRS ${UIS} )

# and finally this will run moc:
QT4_WRAP_CPP( MOC_SRCS ${MOC_HDRS} ${UI_HDRS} )

# we need this to be able to include headers produced by uic in our code
# (CMAKE_BINARY_DIR holds a path to the build directory, while INCLUDE_DIRECTORIES() works just like INCLUDEPATH from qmake)
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${OPENGL_INCLUDE_DIR})

# here we instruct CMake to build executable from all of the source files
ADD_EXECUTABLE( LevelEditor ${HDRS} ${SRCS} ${MOC_SRCS} ${RC_SRCS} ${UI_HDRS} )

# last thing we have to do is to tell CMake what libraries our executable needs,
# luckily FIND_PACKAGE prepared QT_LIBRARIES variable for us:
TARGET_LINK_LIBRARIES( LevelEditor ${QT_LIBRARIES} ${OPENGL_LIBRARIES})

最佳答案

将qt5 添加到CMakeLists.txt 与qt4 不同,您可以找到许多有用的链接,例如this。 ,顺便说一句,我的 ubuntu 版本是 12.04,我安装了没有 apt-get 的 qt,我使用这种格式在我的 cmakelists.txt 中找到 qt:

find_package(Qt5Widgets)

include_directories(${Qt5Widgets_INCLUDES}
/opt/Qt5.0.2/5.0.2/gcc/include/QtGui
/opt/Qt5.0.2/5.0.2/gcc/include/QtCore
/opt/Qt5.0.2/5.0.2/gcc/include/QtNetwork
/opt/Qt5.0.2/5.0.2/gcc/include/QtWidgets
/opt/Qt5.0.2/5.0.2/gcc/include/QtWebKit
/opt/Qt5.0.5/5.0.5/gcc/include/QtScript
)

add_definitions(${Qt5Widgets_DEFINITIONS})

set(CMAKE_CXX_FLAGS "${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS} -I/opt/Qt5.0.2/5.0.2` /gcc/include -L/opt/Qt5.0.2/5.0.2/gcc/lib -DQT5")`

你应该用我的地址替换你的头文件的地址,你也应该这样使用 target_link_libraries:

target_link_libraries(LevelEditor ${OPENGL_LIBRARIES} ${Qt5Widgets_LIBRARIES})

关于Ubuntu 13.04 CMake 和 Qt4 和 Qt5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16523635/

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