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

时间:2022-09-06 01:52:26

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. The issue is that it, along with existing CMake for AVR examples, are all for Linux based systems.

我的出发点是这个例子。问题是,它和AVR示例的现有CMake都适用于基于Linux的系统。

What I've tried is installing WinAVR to get the executables. I've modified the CMakeList.txt so the program names contain the following:

我尝试安装WinAVR来获得可执行文件。我已经修改了CMakeList。因此程序名包含以下内容:

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 pass 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.

1 个解决方案

#1


0  

I use cmake and avr on windows and on linux. The syntax is the same. Why do you want to use cygwin in the mid of that?

我在windows和linux上使用cmake和avr。语法是一样的。为什么你想用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. You need to do this because when cmake starts it try to compile a simple program and it try to run it. If you are using an avr compiler on a computer cmake can't run the executable, so it fails.

无论如何,您都没有显示工具链文件。当使用cmake交叉编译时,您需要提供一个工具链文件,在该文件中设置与编译器相关的所有配置。您需要这样做,因为当cmake启动时,它试图编译一个简单的程序,并试图运行它。如果您在计算机上使用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

#1


0  

I use cmake and avr on windows and on linux. The syntax is the same. Why do you want to use cygwin in the mid of that?

我在windows和linux上使用cmake和avr。语法是一样的。为什么你想用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. You need to do this because when cmake starts it try to compile a simple program and it try to run it. If you are using an avr compiler on a computer cmake can't run the executable, so it fails.

无论如何,您都没有显示工具链文件。当使用cmake交叉编译时,您需要提供一个工具链文件,在该文件中设置与编译器相关的所有配置。您需要这样做,因为当cmake启动时,它试图编译一个简单的程序,并试图运行它。如果您在计算机上使用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