我使用这个工具链进行交叉编译(从opensuse 64bit到windows 32bit):
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Windows)
# which compilers to use for C and C++
SET(CMAKE_C_COMPILER /usr/bin/i686-w64-mingw32-gcc)
SET(CMAKE_CXX_COMPILER /usr/bin/i686-w64-mingw32-g++)
SET(CMAKE_RC_COMPILER /usr/bin/i686-w64-mingw32-windres)
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32)
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
然后像这样使用它: cmake -DCMAKE_TOOLCHAIN_FILE =〜/ zCross / mingw32.cmake。 但每次我尝试使用这个cmake文件时:
project(ut6)
cmake_minimum_required(VERSION 2.6)
find_package(Qt4 REQUIRED)
include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
set(ut6_SRCS ut6.cpp main.cpp)
qt4_automoc(${ut6_SRCS})
add_executable(ut6 ${ut6_SRCS})
target_link_libraries(ut6 ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})
install(TARGETS ut6 RUNTIME DESTINATION bin)
这个控制台输出是:
CMake Warning at /usr/share/cmake/Modules/FindQt4.cmake:657 (message):
/usr/bin/qmake reported QT_INSTALL_LIBS as "/usr/lib64" but QtCore could
not be found there. Qt is NOT installed correctly for the target build
environment.
Call Stack (most recent call first):
CMakeLists.txt:3 (find_package)
CMake Error at /usr/share/cmake/Modules/FindQt4.cmake:661 (message):
Could NOT find QtCore. Check
/home/aked/projects/ut6/CMakeFiles/CMakeError.log for more details.
Call Stack (most recent call first):
CMakeLists.txt:3 (find_package)
看起来它正在寻找本地系统上的库而不是mingw32位置,在交叉编译时我仍然可以使用find_package吗?
现在我只是手动链接libQtCore.dll.a,它可以工作,但是当我想使用qt4_automoc生成moc信息时,我又被卡住了。谢谢你的帮助
答案 0 :(得分:2)
找到解决方案,查找qt4只是在交叉编译时不起作用,你必须手动设置所有内容:(在工具链文件中)(每个系统上的目录可能不一样)
set(QT_BINARY_DIR /usr/i686-w64-mingw32/sys-root/mingw/bin/)
set(QT_LIBRARY_DIR ${KDE_PREFIX}/lib)
set(QT_QTCORE_LIBRARY ${KDE_PREFIX}/lib/libQtCore4.a)
set(QT_QTCORE_INCLUDE_DIR ${KDE_PREFIX}/include/QtCore)
set(QT_MKSPECS_DIR ${KDE_PREFIX}/mkspecs)
set(QT_MOC_EXECUTABLE ${QT_BINARY_DIR}/moc)
set(QT_QMAKE_EXECUTABLE ${QT_BINARY_DIR}/qmake)
set(QT_UIC_EXECUTABLE ${QT_BINARY_DIR}/uic)