如何配置ev3dev CMake以使用交叉编译器

如何配置ev3dev CMake以使用交叉编译器,cmake,toolchain,Cmake,Toolchain,我正在尝试为我的EV3构建EV3DEV C++绑定(参见)。但是CMake没有使用我的交叉编译器工具链。我已经成功地安装了CodeSourcery工具链,构建了一个简单的hello world应用程序,并在我的brick上运行了它。那很好用。问题是CMake使用我主机的g++编译器而不是工具链。我熟悉linux和交叉编译器,但我是一个彻头彻尾的cmakenoob。所以我怀疑CMake是我错的地方 我在CMakeLists.txt中添加了以下行: set(CMAKE_C_COMPILER "

我正在尝试为我的EV3构建EV3DEV C++绑定(参见)。但是CMake没有使用我的交叉编译器工具链。我已经成功地安装了CodeSourcery工具链,构建了一个简单的hello world应用程序,并在我的brick上运行了它。那很好用。问题是CMake使用我主机的g++编译器而不是工具链。我熟悉linux和交叉编译器,但我是一个彻头彻尾的cmakenoob。所以我怀疑CMake是我错的地方

我在CMakeLists.txt中添加了以下行:

set(CMAKE_C_COMPILER    "/cygdrive/c/Users/me/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin/arm-none-linux-gnueabi-gcc.exe")
set(CMAKE_CXX_COMPILER  "/cygdrive/c/Users/me/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin/arm-none-linux-gnueabi-g++.exe")
以下是主机gcc编译器:

$ gcc --version
gcc (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ /cygdrive/c/Users/me/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin/arm-none-linux-gnueabi-gcc.exe --version
arm-none-linux-gnueabi-gcc.exe (Sourcery CodeBench Lite 2014.05-29) 4.8.3 20140320 (prerelease)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
以及目标工具链gcc编译器:

$ gcc --version
gcc (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ /cygdrive/c/Users/me/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin/arm-none-linux-gnueabi-gcc.exe --version
arm-none-linux-gnueabi-gcc.exe (Sourcery CodeBench Lite 2014.05-29) 4.8.3 20140320 (prerelease)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
编译器是不同的版本,因此很容易区分

现在是cmake构建的终端会话:

$ mkdir build
$ cd build
$ cmake ../ -DEV3DEV_PLATFORM=EV3
-- No build type selected, default to RelWithDebInfo
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
CMake Warning at /usr/share/cmake-3.6.2/Modules/Platform/CYGWIN.cmake:15 (message):
  CMake no longer defines WIN32 on Cygwin!

  (1) If you are just trying to build this project, ignore this warning or
  quiet it by setting CMAKE_LEGACY_CYGWIN_WIN32=0 in your environment or in
  the CMake cache.  If later configuration or build errors occur then this
  project may have been written under the assumption that Cygwin is WIN32.
  In that case, set CMAKE_LEGACY_CYGWIN_WIN32=1 instead.

  (2) If you are developing this project, add the line

    set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required

  at the top of your top-level CMakeLists.txt file or set the minimum
  required version of CMake to 2.8.4 or higher.  Then teach your project to
  build on Cygwin without WIN32.
Call Stack (most recent call first):
  /usr/share/cmake-3.6.2/Modules/CMakeSystemSpecificInformation.cmake:36 (include)
  CMakeLists.txt:7 (project)


-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++.exe
-- Check for working CXX compiler: /usr/bin/c++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /cygdrive/c/Users/me/Documents/AppProjects/ev3dev-lang-cpp/build
$
CMake显然在使用cygwin主机gcc/g++编译器,尽管我已经尝试将其配置为使用工具链。我哪里做错了


编辑:这不是的副本。我确实使用了google,CMake wiki()上的交叉编译指令明确规定使用SET()。问题是CMake要求在PROJECT()之前设置编译器。我只是将SET()行移到PROJECT()上方,然后CMake找到了编译器。

可能重复的,请在发布前使用谷歌或搜索功能。此外,您尝试使用的方法是非常不推荐的,应该不惜一切代价避免使用。