gpt4 book ai didi

c - 阿杜诺 & C : put a function and global variable in external file

转载 作者:太空狗 更新时间:2023-10-29 15:29:43 26 4
gpt4 key购买 nike

这应该是个简单的问题。我正在尝试将代码拆分为草图中的两个文件:

测试.ino:

void setup(){}
void loop(){ fn(); }

测试.c:

char myChar = '?';
void fn(){ myChar++; }

我试过使用具有各种配置的 test.h 文件,例如具有以下行:

  • extern char myChar;,
  • char myChar;
  • void fn();
  • extern void fn();

以及在不同文件中包含 test.c 和 test.h 文件的各种组合,但我总是遇到一个或另一个编译器错误,例如:

test.cpp.o:(.data.myChar+0x0): multiple definition of `myChar'

test.c.o:(.data.myChar+0x0): first defined here

或者

test.cpp.o: In function `setup':

C:\Program Files\arduino-1.0.4/test.ino:4: undefined reference to `fn()'

我真的用这个把我的头发拉出来。任何帮助将不胜感激

最佳答案

Arduino IDE 真正适合初学者。随着您变得更好,您可能希望分支到更传统的编程工具。

Arduino 项目实际上只是 c/c++ 应用程序。在这方面,您拥有整个 c/c++ 社区的支持。他们最喜欢和最鄙视的工具之一叫做 make。您可以使用它来部署和构建您的项目。这是一个很好的起点。 http://ed.am/dev/make/arduino-mk/arduino.mk

关于c - 阿杜诺 & C : put a function and global variable in external file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16510521/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com