Visual Studio Ide for Arduino
https://www.visualmicro.com/forums/YaBB.pl
>> >> 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 10:38pm

Title: How to compile a simple Arduino program?
Post by PNK on Apr 24th, 2019 at 10: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++):
#ifndef _SKETCHWIFI_h
#define _SKETCHWIFI_h

int WiFi_Setup();

#endif


SketchWiFi.c file:

Code (c++):
#include "SketchWiFi.h"

int WiFi_Setup()
{
  // put your setup code here, to run once:

  return 1; // Successful
}


Sketch.ino file:

Code (c++):
#include "SketchWiFi.h"

void setup() {
  Serial.begin(115200);
  Serial.println("Begin setup");

  WiFi_Setup();

  Serial.println("End setup");
}

void loop() {
  // put your main code here, to run repeatedly:
}




https://www.visualmicro.com/forums/YaBB.pl?action=downloadfile;file=SketchIncomeEligible.zip (6416 KB | 5 )

Title: Re: How to compile a simple Arduino program?
Post by PNK on Apr 24th, 2019 at 11: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 3:32pm
That's right. Thanks we are currently revamping the documentation and will make this point clearer for the mode advanced new Arduino users :)

Visual Studio Ide for Arduino » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2019. All Rights Reserved.