如何使用find_package时,使用cmake交叉编译工具链文件



我使用这个工具链交叉编译(从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信息时,我又卡住了。感谢您的帮助

找到了解决方案,当你交叉编译时,发现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)

最新更新