简体   繁体   English

与CMake交叉编译:如何排除默认的qt库,而不是将它们传递给链接器的命令行

[英]Cross-compile with CMake: How to exclude default qt libraries and not to pass them to linker's command line

I want to cross-compile Qt planets demo applicatioin on Linux x64 with CMake for ARM. 我想在Linux x64上使用CMake for ARM交叉编译Qt行星演示应用程序。

I installed arm cross compiler. 我安装了arm交叉编译器。 I've built Qt libs on ARM board and copied them to x64 Linux box's /lib/arm-linux-gnueabihf. 我在ARM板上构建了Qt库并将它们复制到x64 Linux机器的/ lib / arm-linux-gnueabihf。

For qmake I did this with only adding few lines to planets.pro file: 对于qmake,我只使用几行添加到planets.pro文件:

PLATFORM = arm-linux-gnueabihf
QMAKE_CXX = /usr/bin/$$PLATFORM-g++
QMAKE_LINK = /usr/bin/$$PLATFORM-g++
QMAKE_LIBS = -L/usr/$$PLATFORM/lib -L/lib/$$PLATFORM

It compiles successfully and runs perfectly on ARM board. 它成功编译并在ARM板上完美运行。

Now, I want to do this with CMake. 现在,我想用CMake做到这一点。 So, I created the following CMakeLists.txt: 所以,我创建了以下CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)

set(PLATFORM arm-linux-gnueabihf)
set(CMAKE_CXX_COMPILER /usr/bin/${PLATFORM}-g++)
link_directories(/usr/${PLATFORM}/lib /lib/${PLATFORM})

file(GLOB_RECURSE HEADERS "*.hpp")
file(GLOB SOURCES "*.cpp")

set(CMAKE_AUTOMOC ON)

find_package(Qt5Qml REQUIRED)
find_package(Qt5Quick REQUIRED)

add_executable(planets-qml ${SOURCES})

target_link_libraries(planets-qml
    Qt5::Qml
    Qt5::Quick
)

With this I have the following warning in Qt Creator's log: 有了这个,我在Qt Creator的日志中有以下警告:

Cannot generate a safe runtime search path for target planets-qml because
files in some directories may conflict with libraries in implicit
directories:

runtime library [libGL.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
  /lib/arm-linux-gnueabihf

Then, I'm building it, and I got linker error: 然后,我正在构建它,我收到链接器错误:

/home/dev/Qt5.7.0/5.7/gcc_64/lib/libQt5Quick.so.5.7.0: 
file not recognized: File format not recognized

I assume this happens because linker tries to link x64 Qt libraries to ARM binary. 我认为这是因为链接器试图将x64 Qt库链接到ARM二进制文件。 But why can't it find libs from /lib/arm-linux-gnueabihf ? 但为什么不能从/ lib / arm-linux-gnueabihf找到libs?

I found the command to the linker in the file linker.txt: 我在文件linker.txt中找到了链接器的命令:

/usr/bin/arm-linux-gnueabihf-g++ 
    CMakeFiles/planets-qml.dir/main.cpp.o 
    CMakeFiles/planets-qml.dir/planets-qml_automoc.cpp.o  
    -o planets-qml  
    -L/usr/arm-linux-gnueabihf/lib  -L/lib/arm-linux-gnueabihf 
    /home/dev/Qt5.7.0/5.7/gcc_64/lib/libQt5Quick.so.5.7.0 
    /home/dev/Qt5.7.0/5.7/gcc_64/lib/libQt5Qml.so.5.7.0 
    /home/dev/Qt5.7.0/5.7/gcc_64/lib/libQt5Network.so.5.7.0 
    /home/dev/Qt5.7.0/5.7/gcc_64/lib/libQt5Gui.so.5.7.0 
    /home/dev/Qt5.7.0/5.7/gcc_64/lib/libQt5Core.so.5.7.0 
    -Wl,-rpath,/usr/arm-linux-gnueabihf/lib:/lib/arm-linux-gnueabihf:/home/dev/Qt5.7.0/5.7/gcc_64/lib 

So, the question is: How to exclude these /home/dev/Qt5... entries and not to pass them to the linker? 所以,问题是:如何排除这些/ home / dev / Qt5 ...条目而不是将它们传递给链接器? What CMake command should I use in CMakeLists.txt file? 我应该在CMakeLists.txt文件中使用什么CMake命令?

Problem is that you are looking at the wrong QT directory. 问题是你正在查看错误的QT目录。 You need to recompile Qt for ARM. 您需要为ARM重新编译Qt。 Then set Qt5_DIR before find_package calls. 然后在find_package调用之前设置Qt5_DIR

set(Qt5_DIR  <path-to-Qt>/lib/cmake/Qt5/)

Your <path-to-Qt>/lib/cmake/Qt5/ should look like this: 您的<path-to-Qt>/lib/cmake/Qt5/应该如下所示:

$ ls <path-to-Qt>/lib/cmake/Qt5/
Qt5Config.cmake        Qt5ConfigVersion.cmake 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM