Compiler issues with adding a library

I am using Arduino 1.8.4 and i am running into issues with running a library I had made. I followed this guide (Arduino - LibraryTutorial) in configuring both the .h and .cpp in the appropriate location and folders.

//#include "roboclaw_ext.h"


#include <avr/wdt.h>
//#include "Arduino.h"
#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
  #else
  #include "WProgram.h"
  #endif
#include <Wire.h>

#define off 127



//------------------------------------------ Header ------------------------------------
class roboclaw_ext {
   public:
  #define rcmotor_L ForwardBackwardM1
  #define rcmotor_R ForwardBackwardM2
  #define adtracks 0x80
  #define adauger 0x81
  #define adspinner 0x82
  
   roboclaw_ext(void);
   void rctrackL(int velocity);
   void rctrackR(int velocity);
   void MotorLV(int velocity);
   void MotorRV(int velocity);
  
   private:
   int v;
};



class roboclaw_ext test;
  
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
//
  test.rctrackL(off);
  test.rctrackR(off);

}


//------------------------------------ CPP -------------------------------------------
 roboclaw_ext::roboclaw_ext(void){
  v=1;
 };
 
  void roboclaw_ext::rctrackL(int velocity)
{
  v=velocity;
  MotorLV(v);
};

  void roboclaw_ext::rctrackR(int velocity)
{
  v=velocity;
  MotorRV(v);
};

void roboclaw_ext::MotorLV(int ve)
{
//  roboclaw.rcmotor_L(adtracks,ve);
};
void roboclaw_ext::MotorRV(int ve)
{
//  roboclaw.rcmotor_R(adtracks,ve);
};
//--------------------------------------------------------------------------------------

When I quote off the the cpp and h components and add the #include “roboclaw_ext.h” I run into a string of errors. This confused me since the code in the header and cpp files are identical.

I will also include the .h and .cpp files that are in my library.

roboclaw_ext.h:

#ifndef roboclaw_ext
#define roboclaw_ext

#include "RoboClaw.h"
#if defined(ARDUINO) && ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif


class roboclaw_ext {
   public:
	
   #define rcmotor_L ForwardBackwardM1
   #define rcmotor_R ForwardBackwardM2
   #define adtracks 0x80
   #define adauger 0x81
   #define adspinner 0x82
  
   roboclaw_ext(void);
   void rctrackL(int velocity);
   void rctrackR(int velocity);
   void MotorLV(int velocity);
   void MotorRV(int velocity);
  
   private:
   int v;
};
#endif

roboclaw_ext.cpp:

#include "roboclaw_ext.h"

 roboclaw_ext::roboclaw_ext(void){
  v=1;
 };
 
  void roboclaw_ext::rctrackL(int velocity)
{
  v=velocity;
  MotorLV(v);
};

  void roboclaw_ext::rctrackR(int velocity)
{
  v=velocity;
  MotorRV(v);
};

void roboclaw_ext::MotorLV(int ve)
{
//  roboclaw.rcmotor_L(adtracks,ve);
};
void roboclaw_ext::MotorRV(int ve)
{
//  roboclaw.rcmotor_R(adtracks,ve);
};

Why are you using #define inside your class? You do not declare class members like that. And what errors do you get?

Arduino: 1.8.4 (Windows 7), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from C:\Users\Johnathan\Desktop\arduino-1.8.4\A_Drone_API_TEST\test_api\Drone_main\Drone_main.ino:1:0:

C:\Users\Johnathan\Documents\Arduino\libraries\roboclaw_ext/roboclaw_ext.h:21:17: error: expected unqualified-id before 'void'

    roboclaw_ext(void);

                 ^

C:\Users\Johnathan\Documents\Arduino\libraries\roboclaw_ext/roboclaw_ext.h:21:17: error: expected ')' before 'void'

C:\Users\Johnathan\Documents\Arduino\libraries\roboclaw_ext/roboclaw_ext.h:12:20: error: an anonymous struct cannot have function members

 class roboclaw_ext {

                    ^

C:\Users\Johnathan\Documents\Arduino\libraries\roboclaw_ext/roboclaw_ext.h:29:1: error: abstract declarator '<anonymous class>' used as declaration

 };

 ^

C:\Users\Johnathan\Desktop\arduino-1.8.4\A_Drone_API_TEST\test_api\Drone_main\Drone_main.ino: In function 'void loop()':

Drone_main:48: error: expected unqualified-id before '.' token

   test.rctrackL(off);

       ^

Drone_main:49: error: expected unqualified-id before '.' token

   test.rctrackR(off);

       ^

exit status 1
expected unqualified-id before '.' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

These are the errors i get when I use #include “roboclaw_ext.h”.

There's your problem:

#ifndef roboclaw_ext
#define roboclaw_ext

Think hard:

  • What does the #define do?
  • What happens when roboclaw_ext appears in the code?

I was wanting to change some of the definitions in Roboclaw.h since I found the name make it less clear on what it does in my application (I am controlling multiple motor controllers doing different things). Do I need to put the #define in the cpp?