2

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:

#ifndef _SKETCHWIFI_h
#define _SKETCHWIFI_h

int WiFi_Setup();

#endif

SketchWiFi.c file:

#include "SketchWiFi.h"

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

  return 1; // Successful
}

Sketch.ino file:

#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:
}

Directory structure:

enter image description here

Project Structure in Visual Studio 2017

enter image description here

Project structure in Arduino IDE enter image description here

6
  • Sorry, my mistake Commented Apr 24, 2019 at 20:43
  • This might help you : github.com/arduino/Arduino/wiki/Build-Process Commented Apr 24, 2019 at 20:50
  • You don't seem to use the Arduino IDE to compile your project. How do you force SketchWiFi.c to be one of your source files ? Add a SketchWiFi.cpp to your project with that code. Commented Apr 24, 2019 at 20:50
  • are you using Arduino IDE to build? Commented Apr 24, 2019 at 20:55
  • Yes. I have compiled in both environments, Visual Studio 2017 and Arduino IDE. Commented Apr 24, 2019 at 21:03

1 Answer 1

2

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()' with in a class and now it compiles successfully.

class WifiNetwork
{
protected:

public:
    void WiFi_Setup();
};

It seems Arduino wants everything to live in classes.

Sign up to request clarification or add additional context in comments.

1 Comment

could you show how the .h, and .c files were modified?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.