c - 在 Cygwin 或 MinGW 中将 CMake 与 AVR 工具链结合使用

标签 c cygwin mingw avr clion

我目前正在尝试设置工具链,以便我可以从 CLion 构建 AVR 项目。

我的起点是 this ,特别是 Blink 示例。问题在于,它与现有的 CMake for AVR 示例一起都适用于基于 Linux 的系统。

我尝试过安装 WinAVR 来获取可执行文件。我修改了 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")

在使用 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

有没有办法让 CMake 以它可以使用的格式传递 avr-gcc 参数?

作为引用,这是完整的输出:

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.

最佳答案

我在 Windows 和 Linux 上使用 cmake 和 avr。 语法是一样的。为什么要在中间使用 cygwin?

无论如何,您都没有显示您的工具链文件。 使用 cmake 进行交叉编译时,您需要提供一个工具链文件,您可以在其中设置与编译器相关的所有配置。 您需要这样做,因为当 cmake 启动时,它会尝试编译一个简单的程序并尝试运行它。如果您在计算机上使用 avr 编译器,则 cmake 无法运行可执行文件,因此它会失败。

您需要格外小心,将此命令包含在工具链中:

SET(CMAKE_SYSTEM_NAME Generic)

需要它来跳过此编译,以避免失败。

我认为这是一本很好的读物,从哪里开始:

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

关于c - 在 Cygwin 或 MinGW 中将 CMake 与 AVR 工具链结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28170625/

相关文章:

C: fgets() 和命令行输入

c - 使用递归进行练习时的缺点

git - git-config(1) 说 "colors are used only when the output is to a terminal"是什么意思?

cygwin - cygpath 无法将 Windows 路径转换为 ​​Linux 路径

windows - Windows 上的 PCSC-Lite 代码

c++ - 如何使用 MinGW gdb 调试器在 Windows 中调试 C++ 程序?

mingw - 无法从 Sourceforge 下载 MinGW

C编程调用指针的指针

c - 从函数 C 分配数组和赋值

ruby-on-rails - 尝试在 Windows 上通过 Cygwin 调用 rails 命令时出错(通过 railsinstaller 安装)