Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
 
When Logging a Support Issue in the Forum, please ensure you have also:-
  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
Support requests without the output above may be impossible to answer, so please help us to help you
 
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
 
Page Index Toggle Pages: 1
Send Topic Print
How to compile a simple Arduino program? (Read 285 times)
PNK
Newbies
*
Offline



Posts: 2
How to compile a simple Arduino program?
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\SketchIncomeElig
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':

C:\Users\C113850\source\repos\Income_Eligible_Price_Display\src\SketchIncomeElig
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++):
#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:
} 




Back to top
« Last Edit: Apr 24th, 2019 at 10:44pm by PNK »  
 
IP Logged
 
PNK
Newbies
*
Offline



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



Posts: 10146
United Kingdom
Re: How to compile a simple Arduino program?
Reply #2 - 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 Smiley
Back to top
 
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print