简体   繁体   English

在Cygwin或MinGW中使用CMake和AVR工具链

[英]Using CMake with AVR Toolchain in Cygwin or MinGW

I'm currently trying to get a toolchain setup so I can build an AVR project from CLion. 我目前正在尝试设置工具链,以便我可以从CLion构建一个AVR项目。

My starting point is this , specifically, the Blink example. 我的出发点是这个 ,特别是Blink的例子。 The issue is that it, along with existing CMake for AVR examples, are all for Linux based systems. 问题在于,它与现有的CMake for AVR示例一起,都是基于Linux的系统。

What I've tried is installing WinAVR to get the executables. 我尝试过安装WinAVR来获取可执行文件。 I've modified the CMakeList.txt so the program names contain the following: 我修改了CMakeList.txt,因此程序名称包含以下内容:

set(AVRCPP   "C:/WinAVR-20100110/bin/avr-g++")
set(AVRC     "C:/WinAVR-20100110/bin/avr-gcc")
set(AVRSTRIP "C:/WinAVR-20100110/bin/avr-strip")
set(OBJCOPY  "C:/WinAVR-20100110/bin/avr-objcopy")
set(OBJDUMP  "C:/WinAVR-20100110/bin/avr-objdump")
set(AVRSIZE  "C:/WinAVR-20100110/bin/avr-size")
set(AVRDUDE  "C:/WinAVR-20100110/bin/avrdude")
set(AVRAS  "C:/WinAVR-20100110/bin/avr-as")

While using the Cygwin environment, CMake has no issue finding my compilers, but when I try to build the project, avr-gcc is being passed parameters in Linux format. 在使用Cygwin环境时,CMake找到我的编译器没有问题,但是当我尝试构建项目时,avr-gcc正在以Linux格式传递参数。

C:/WinAVR-20100110/bin/avr-gcc.exe -o CMakeFiles/cmTryCompileExec420260872.dir/testCCompiler.c.obj -c /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp/testCCompiler.c
avr-gcc.exe: /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp/testCCompiler.c: No such file or directory

Is there a way to have CMake pass avr-gcc arguments in a format it can work with? 有没有办法让CMake以可以使用的格式传递avr-gcc参数?

For reference, this is the full output: 作为参考,这是完整的输出:

Error:The C compiler "C:/WinAVR-20100110/bin/avr-gcc" is not able to compile a simple test program.
It fails with the following output:
 Change Dir: /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp
Run Build Command:/usr/bin/make.exe "cmTryCompileExec420260872/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec420260872.dir/build.make CMakeFiles/cmTryCompileExec420260872.dir/build
make[1]: Entering directory '/cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp'
/usr/bin/cmake.exe -E cmake_progress_report /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec420260872.dir/testCCompiler.c.obj
C:/WinAVR-20100110/bin/avr-gcc.exe -o CMakeFiles/cmTryCompileExec420260872.dir/testCCompiler.c.obj -c /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp/testCCompiler.c
avr-gcc.exe: /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp/testCCompiler.c: No such file or directory
avr-gcc.exe: no input files
CMakeFiles/cmTryCompileExec420260872.dir/build.make:60: recipe for target 'CMakeFiles/cmTryCompileExec420260872.dir/testCCompiler.c.obj' failed
make[1]: Leaving directory '/cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp'
make[1]: *** [CMakeFiles/cmTryCompileExec420260872.dir/testCCompiler.c.obj] Error 1
Makefile:117: recipe for target 'cmTryCompileExec420260872/fast' failed
make: *** [cmTryCompileExec420260872/fast] Error 2
CMake will not be able to correctly generate this project.

I use cmake and avr on windows and on linux. 我在Windows和Linux上使用cmake和avr。 The syntax is the same. 语法是一样的。 Why do you want to use cygwin in the mid of that? 为什么你想在中间使用cygwin?

In any case you didn't show your toolchain file. 在任何情况下,您都没有显示您的工具链文件。 When cross compiling using cmake you need to provide a toolchain file where you set all the configuration related to the compiler. 当使用cmake进行交叉编译时,您需要提供一个工具链文件,您可以在其中设置与编译器相关的所有配置。 You need to do this because when cmake starts it try to compile a simple program and it try to run it. 你需要这样做,因为当cmake启动时,它尝试编译一个简单的程序,并尝试运行它。 If you are using an avr compiler on a computer cmake can't run the executable, so it fails. 如果您在计算机上使用avr编译器,则cmake无法运行可执行文件,因此失败。

You need to put an extra care including this command in the toolchain: 您需要在工具链中额外注意包括此命令:

SET(CMAKE_SYSTEM_NAME Generic)

it is needed for skip this compilation and so to avoid the failure. 跳过此编译需要它,以避免失败。

I think this is a good read where to begin: 我认为这是一个很好的阅读从哪里开始:

http://playground.arduino.cc/Code/CmakeBuild http://playground.arduino.cc/Code/CmakeBuild

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

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