VS Arduino | |
>> >> How to compile a simple Arduino program?
https://www.visualmicro.com/forums/YaBB.pl?num=1556141934 Message started by PNK on Apr 24th, 2019 at 9:38pm |
Title: How to compile a simple Arduino program? Post by PNK on Apr 24th, 2019 at 9:38pm
I am starting to learn / program the Arduino and I don't understand why I am getting syntax errors upon compiling my program in Visual Studio 2017 with Visual Micro or with the Arduino IDE.
Compiling output error from Visual Studio 2017: sketch\SketchIncomeEligible.ino.cpp.o:(.text.setup+0x0): undefined reference to `WiFi_Setup()' sketch\SketchIncomeEligible.ino.cpp.o: In function `setup': C:\Users\C113850\source\repos\Income_Eligible_Price_Display\src\SketchIncomeEligible\SketchIncomeEligible/SketchIncomeEligible.ino:6: undefined reference to `WiFi_Setup()' collect2.exe: error: ld returned 1 exit status exit status 1 Error compiling for board Adafruit Feather HUZZAH ESP8266. Compiling error from Arduino IDE: Arduino: 1.8.9 (Windows 10), Board: "Adafruit Feather HUZZAH ESP8266, 80 MHz, Flash, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200" sketch\SketchIncomeEligible.ino.cpp.o:(.text.setup+0x0): undefined reference to `WiFi_Setup()' sketch\SketchIncomeEligible.ino.cpp.o: In function `setup': C:\Users\C113850\source\repos\Income_Eligible_Price_Display\src\SketchIncomeEligible\SketchIncomeEligible/SketchIncomeEligible.ino:6: undefined reference to `WiFi_Setup()' collect2.exe: error: ld returned 1 exit status exit status 1 Error compiling for board Adafruit Feather HUZZAH ESP8266. This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences. The following is my code: SketchWiFi.h file: Code (c++):
SketchWiFi.c file: Code (c++):
Sketch.ino file: Code (c++):
SketchIncomeEligible.zip (Attachment deleted)
|
Title: Re: How to compile a simple Arduino program? Post by PNK on Apr 24th, 2019 at 10:04pm
Per a suggestion posted, I read on GitHub the following:
No pre-processing is done to files in a sketch with any extension other than .ino. Additionally, .h files in the sketch are not automatically #included from the main sketch file. Further, if you want to call functions defined in a .c file from a .cpp file (like one generated from your sketch), you'll need to wrap its declarations in an 'extern "C" {}' block that is defined only inside of C++ files. So that explains my problem. I enclosed my simple function 'WiFi_Setup()' within a class and now it compiles successfully. class WifiNetwork { protected: public: void WiFi_Setup(); }; It seems Arduino wants everything to live in classes. |
Title: Re: How to compile a simple Arduino program? Post by Visual Micro on Apr 25th, 2019 at 2:32pm
That's right. Thanks we are currently revamping the documentation and will make this point clearer for the mode advanced new Arduino users :)
|
VS Arduino » Powered by YaBB 2.6.12! YaBB Forum Software © 2000-2024. All Rights Reserved. |