Reputation: 169
I want to cross-compile Qt planets demo applicatioin on Linux x64 with CMake for ARM.
I installed arm cross compiler. I've built Qt libs on ARM board and copied them to x64 Linux box's /lib/arm-linux-gnueabihf.
For qmake I did this with only adding few lines to planets.pro file:
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.
Now, I want to do this with CMake. So, I created the following 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:
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. But why can't it find libs from /lib/arm-linux-gnueabihf ?
I found the command to the linker in the file 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? What CMake command should I use in CMakeLists.txt file?
Upvotes: 5
Views: 3521
Reputation: 3677
Problem is that you are looking at the wrong QT directory.
You need to recompile Qt for ARM. Then set Qt5_DIR
before find_package
calls.
set(Qt5_DIR <path-to-Qt>/lib/cmake/Qt5/)
Your <path-to-Qt>/lib/cmake/Qt5/
should look like this:
$ ls <path-to-Qt>/lib/cmake/Qt5/
Qt5Config.cmake Qt5ConfigVersion.cmake
Upvotes: 2