Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to compile a simple Arduino program? (Read 1174 times)
PNK
Newbies
*
Offline


Posts: 2
Joined: Apr 24th, 2019
How to compile a simple Arduino program?
Apr 24th, 2019 at 9:38pm
Print Post  
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':

ible\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':

ible\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++)
Select All
#ifndef _SKETCHWIFI_h
#define _SKETCHWIFI_h

int WiFi_Setup();

#endif 



SketchWiFi.c file:
Code (C++)
Select All
#include "SketchWiFi.h"

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

  return 1; // Successful
} 



Sketch.ino file:
Code (C++)
Select All
#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:
} 




« Last Edit: Apr 24th, 2019 at 9:44pm by PNK »  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
PNK
Newbies
*
Offline


Posts: 2
Joined: Apr 24th, 2019
Re: How to compile a simple Arduino program?
Reply #1 - Apr 24th, 2019 at 10:04pm
Print Post  
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.
« Last Edit: Apr 24th, 2019 at 10:13pm by PNK »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to compile a simple Arduino program?
Reply #2 - Apr 25th, 2019 at 2:32pm
Print Post  
That's right. Thanks we are currently revamping the documentation and will make this point clearer for the mode advanced new Arduino users Smiley
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint