【问题标题】:Arduino - Uploading sketch in vs code failed, But Arduino IDE OKArduino - 在 vs 代码中上传草图失败,但 Arduino IDE 正常
【发布时间】:2022-01-01 03:22:29
【问题描述】:
#include <DS3231.h>
DS3231  rtc(SDA, SCL);

void setup()
{

  Serial.begin(9600);
  rtc.begin();
  Serial.println("Setup...");
}

void loop()
{
   Serial.println("Loop...");
  // // Send time
  Serial.println(rtc.getTimeStr());
  delay(2000);
}

这是简单的代码。在Arduino IDE中上传这个skecth效果很好,我可以看到串行日志

Setup...
Loop...
12:18:01
Loop...
12:18:03
Loop...
12:18:05

没问题。 但是当我在VS Code上传这段代码时,它就不行了。

下面的输出

[Starting] Uploading sketch 'smartfarm.ino'
Please see the build logs in output path: c:\Projects\ArduinoOutput
설정파일 로딩... // loading configuration...
패키지 초기화... // initializing packages...
보드 준비...     // ready to board...
확인...          // ok...
C:\Users\appton-2\Documents\Arduino\libraries\DS3231/DS3231.h:77:7: warning: type 'struct DS3231' violates the C++ One Definition Rule [-Wodr]
class DS3231
       ^
C:\Users\appton-2\Documents\Arduino\libraries\DS3231\DS3231.h:62:7: note: a different type is defined in another translation unit
^
C:\Users\appton-2\Documents\Arduino\libraries\DS3231/DS3231.h:100:11: note: the first difference of corresponding definitions is field '_scl_pin'
uint8_t _scl_pin;
           ^
C:\Users\appton-2\Documents\Arduino\libraries\DS3231\DS3231.h:69:13: note: a field with different name is defined in another translation unit
uint8_t  date;
             ^
C:\Users\appton-2\AppData\Local\Temp\ccp574Yq.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_smartfarm.ino.cpp.o.1845':
<artificial>:(.text.startup+0x60): undefined reference to `DS3231::DS3231(unsigned char, unsigned char)'
C:\Users\appton-2\AppData\Local\Temp\ccp574Yq.ltrans0.ltrans.o: In function `setup':
c:\Projects\smartfarm/smartfarm.ino:9: undefined reference to `DS3231::begin()'
C:\Users\appton-2\AppData\Local\Temp\ccp574Yq.ltrans0.ltrans.o: In function `loop':
c:\Projects\smartfarm/smartfarm.ino:16: undefined reference to `DS3231::getTimeStr(unsigned char)'
collect2.exe: error: ld returned 1 exit status
exit status 1
IntelliSense configuration already up to date. To manually rebuild your IntelliSense configuration run "Ctrl+Alt+I"
[Error] Uploading sketch 'smartfarm.ino': Exit with code=1

你知道原因吗?我错过了什么吗?我将 DS3231 库更改为另一个库。

【问题讨论】:

  • “我将 DS3231 库更改为另一个库。”这是什么意思?
  • @JohnFilleau 我删除了 DS3231 库并下载了另一个库并将其放在同一位置。
  • 请显示您放置的库。如果您使用的 DS3231.h 与我正在查看的不同,那么我们无法帮助您。

标签: visual-studio-code arduino


【解决方案1】:

现在效果很好。原因是我猜vs code arduino中的“输出路径”。 vs code 之前要求我输入 outputPath 以进行快速构建。即使我换成新的,也许以前的图书馆仍然存在。我删除了 outputPath 中的所有文件,现在它可以正常工作了:) –

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多