2016-03-24 3 views
3

Ich habe einige Probleme beim Einrichten der Kreuzkompilierung mit CMAKE. Die Toolchain, die ich benutze, ist in yocto erstellt, was perfekt außerhalb von cmake funktioniert.CMAKE fehlt Sysroot beim Quercompilieren

ich eine Anleitung zum Einrichten der folgenden Toolchain-Datei ausgeführt habe:

SET(CMAKE_SYSTEM_NAME Linux) 
SET(CMAKE_SYSTEM_VERSION 1) 
SET(CMAKE_SYSTEM_PROCESSOR arm) 

# specify the cross compiler 
SET(tools /opt/poky/1.7.1/sysroots/x86_64-pokysdk-linux/usr) 
SET(CMAKE_C_COMPILER ${tools}/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc) 
SET(CMAKE_CXX_COMPILER ${tools}/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc) 

# set sysroot 
SET(CMAKE_SYSROOT /home/sifu/test-yocto/qemuarmdfs) 
#SET(CMAKE_FIND_ROOT_PATH /home/sifu/test-yocto/qemuarm) 

# search for programs in the build host directories 
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 
# for libraries and headers in the target directories 
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 

Und die folgende Fehlermeldung beim Ausführen von cmake

The C compiler 
"/opt/poky/1.7.1/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc" 
is not able to compile a simple test program. 

It fails with the following output: 

Change Dir: /home/sifu/Projects/mv/doublepump-single-pump-sw.ss016m21_swapp/cc/CMakeFiles/CMakeTmp 

Run Build Command:/usr/bin/make "cmTryCompileExec4012536451/fast" 

/usr/bin/make -f CMakeFiles/cmTryCompileExec4012536451.dir/build.make 
CMakeFiles/cmTryCompileExec4012536451.dir/build 

make[1]: Entering directory 
`/home/sifu/Projects/mv/doublepump-single-pump-sw.ss016m21_swapp/cc/CMakeFiles/CMakeTmp' 

/usr/bin/cmake -E cmake_progress_report 
/home/sifu/Projects/mv/doublepump-single-pump-sw.ss016m21_swapp/cc/CMakeFiles/CMakeTmp/CMakeFiles 
1 

Building C object 
CMakeFiles/cmTryCompileExec4012536451.dir/testCCompiler.c.o 


/opt/poky/1.7.1/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc 
-O2 -pipe -g -feliminate-unused-debug-types -o 
CMakeFiles/cmTryCompileExec4012536451.dir/testCCompiler.c.o -c 
/home/sifu/Projects/mv/doublepump-single-pump-sw.ss016m21_swapp/cc/CMakeFiles/CMakeTmp/testCCompiler.c 

Linking C executable cmTryCompileExec4012536451 

/usr/bin/cmake -E cmake_link_script 
CMakeFiles/cmTryCompileExec4012536451.dir/link.txt --verbose=1 

/opt/poky/1.7.1/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc 
-O2 -pipe -g -feliminate-unused-debug-types -Wl,-O1 -Wl,--hash-style=gnu 
-Wl,--as-needed CMakeFiles/cmTryCompileExec4012536451.dir/testCCompiler.c.o 
-o cmTryCompileExec4012536451 -rdynamic 

... (A lot of ld errors similar to the one below) 

/opt/poky/1.7.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.1/ld: 
cannot find crtn.o: No such file or directory 

collect2: error: ld returned 1 exit status 

make[1]: Leaving directory 
`/home/sifu/Projects/mv/doublepump-single-pump-sw.ss016m21_swapp/cc/CMakeFiles/CMakeTmp' 

Wenn ich manuell ausführen, den gcc-Befehl im Protokoll oben beschrieben mit --sysroot =/home/sifu/test-yocto/qemuarmdfs es funktioniert für mich. Warum wird cmake nicht mit dem Sysroot-Flag verwendet, wenn der Pfad zu Sysroot in der Toolchain-Datei hinzugefügt wird.

+0

Sieht aus wie CMake nicht erkennen kann, dass der Compiler die '--sysroot' Option unterstützt. Ist die Zeile 'Die C-Compiler-Identifikation ist GNU' bei der Konfiguration von CMake ausgegeben? BTW, zeigen Sie Toolchain mit fehlerhaften Leerzeichen vor "gnueabi-gcc" in "CMAKE_C_COMPILER" Variablendefinition. Dieser Platz fehlt in Ihrer originalen Toolchain-Datei, oder? – Tsyvarev

+0

Beim Konfigurieren erkennt es den richtigen C-Compiler 'Die C-Compiler-Kennung ist GNU 4.9.1.'. Der Platz in CMAKE_C_COMPILER war nur ein Problem beim Ausschneiden und Einfügen, ich habe die ursprüngliche Frage bearbeitet. – user1178014

+0

Ich bin unsicher, aber wahrscheinlich das CMake-Projekt, das Sie versuchten zu bauen, ändert 'CMAKE_C_FLAGS' irgendwie, so' 'sysroot' Option verschwindet. Könnten Sie versuchen, ein einfaches "Hallo Welt" -Programm mit Ihrer Toolchain zu erstellen? – Tsyvarev

Antwort

0

Ich glaube, Sie brauchen CMAKE_C_FLAGS zu setzen und CMAKE_CXX_FLAGS

Auch ich glaube, Sie brauchen

include(CMakeForceCompiler) 
+0

Es löst mein Problem nicht, es ist immer noch keine Sysroot zum Compiler-Test-Befehl hinzugefügt. Wenn ich jedoch cmake dreimal hintereinander laufen lasse, überspringe ich den Test und ich bekomme etwas Arbeit. – user1178014

4

Ich habe zwei Lösungen für dieses Problem:

  1. ich den folgenden Code verwenden in Die Toolchain-Datei:

    # compiler 
    set(CMAKE_C_COMPILER /path/to/arm-none-linux-gnueabi-gcc) 
    set(CMAKE_CXX_COMPILER /path/to/arm-none-linux-gnueabi-g++) 
    # sysroot location 
    set(MYSYSROOT /path/to/sysroots/cortexa7-vfp-neon-telechips-linux-gnueabi) 
    # compiler/linker flags 
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE) 
    set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE) 
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE) 
    set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE) 
    # cmake built-in settings to use find_xxx() functions 
    set(CMAKE_FIND_ROOT_PATH "${MYSYSROOT}") 
    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 
    
  2. Die zweite Lösung besteht darin, das CMakeForceCompiler-Paket in der Toolchain-Datei zu verwenden. Es sieht anders aus, aber ich habe das gleiche Ergebnis:

    # compiler 
    include(CMakeForceCompiler) 
    cmake_force_c_compiler(/path/to/arm-none-linux-gnueabi-gcc GNU) 
    cmake_force_cxx_compiler(/path/to/arm-none-linux-gnueabi-g++ GNU) 
    # sysroot location 
    set(MYSYSROOT /path/to/sysroots/cortexa7-vfp-neon-telechips-linux-gnueabi) 
    # compiler/linker flags 
    add_definitions("--sysroot=${MYSYSROOT}") 
    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE) 
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE) 
    # cmake built-in settings to use find_xxx() functions 
    set(CMAKE_FIND_ROOT_PATH ${MYSYSROOT}) 
    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 
    

BTW, kann ich CMAKE_SYSROOT Variable nicht verwenden, da es erst seit CMake v3.0 verfügbar.

+0

Sowohl Lösung 1 und CMAKE_SYSROOT funktionieren für mich (NXP QorIQ SDK 2.0 PPC64). Vielen Dank! – Matt