Encoder.h library from pjrc.com not compiling for teensy 4.0

Hi, I just purchased a teensy 4.0 and I am attempting to use some code I had previously written for my Arduino Uno. I want to use the teensy because of the high speed and form factor. The issue I am running into is while I am using the verify button of the Arduino IDE it gives the following error:

C:\Users\Maxunm\AppData\Local\Temp\arduino_build_213092\sketch\GoOnUserInput.ino.cpp.o: In function `Encoder::update(Encoder_internal_state_t*)':

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Encoder/Encoder.h:309: undefined reference to `Encoder::interruptArgs'

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Encoder/Encoder.h:309: undefined reference to `Encoder::interruptArgs'

C:\Users\Maxunm\AppData\Local\Temp\arduino_build_213092\sketch\GoOnUserInput.ino.cpp.o: In function `Encoder::Encoder(unsigned char, unsigned char)':

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Encoder/Encoder.h:97: undefined reference to `Encoder::interruptArgs'

collect2.exe: error: ld returned 1 exit status

Error compiling for board Teensy 4.0.

I have also pasted the full .ino file that I am attempting to compile for the Teensy 4.0 below. What I have been finding about this is that it most likely cannot link the .cpp file for some reason which is where the variable that it says is missing is declared. I just do not know how to get the compiler to correctly pull the .cpp file.

#include <SPI.h>
#include <AMIS30543.h>
#include "C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Encoder\Encoder.h"

const uint8_t amisDirPin = 5;//2;
const uint8_t amisStepPin = 6;//3;
const uint8_t amisSlaveSelect = 4;//SS;

AMIS30543 stepper;
int a = 500;
int b = 270;
int usr;

Encoder slidePos(15, 16); //Use pins 15 + 16 as they are both interupt pins.

void setup()
  // Drive the NXT/STEP and DIR pins low initially.
  digitalWrite(amisStepPin, LOW);
  pinMode(amisStepPin, OUTPUT);
  digitalWrite(amisDirPin, LOW);
  pinMode(amisDirPin, OUTPUT);

  // Give the driver some time to power up.

  // Reset the driver to its default settings.

  // Set the current limit.  You should change the number here to
  // an appropriate value for your particular system.

  // Set the number of microsteps that correspond to one full step.

  // Enable the motor outputs.

void loop()
  while (!Serial) {}
  Serial.print("0 for zero, 6 prints current pos, any other # probes\n"); //Going to write a
  while (!Serial.available()) {}
  while (!Serial.available()) {}
  usr = Serial.parseInt();
  if (usr == 0) {
  } else if (usr == 6) {
  } else {
    // Step in the default direction 1000 times.
    for (unsigned int x = 0; x < 100; x++)
    for (unsigned int x = 0; x < 9900; x++)


    // Step in the other direction 1000 times.
    for (unsigned int x = 0; x < 10000; x++)//while(slidePos.read()>3)

// Sends a pulse on the NXT/STEP pin to tell the driver to take
// one step, and also delays to control the speed of the motor.
void step()
  // The NXT/STEP minimum high pulse width is 2 microseconds.
  digitalWrite(amisStepPin, HIGH);
  digitalWrite(amisStepPin, LOW);

  // The delay here controls the stepper motor's speed.  You can
  // increase the delay to make the stepper motor go slower.  If
  // you decrease the delay, the stepper motor will go fast, but
  // there is a limit to how fast it can go before it starts
  // missing steps.

// Writes a high or low value to the direction pin to specify
// what direction to turn the motor.
void setDirection(bool dir)
  // The NXT/STEP pin must not change for at least 0.5
  // microseconds before and after changing the DIR pin.
  digitalWrite(amisDirPin, dir);

void output() {
  Serial.print("mm: ");
  Serial.print((float)slidePos.read() / 200.0, DEC);
  Serial.print("\npulses: ");
  Serial.print(slidePos.read(), DEC);

You're probably better of asking on the PJRC Forums.

Thanks for the sugestion of the Pjrc forums, I have also submitted this question over there.

Unfortunately I think this is an error actually with the Arduino IDE not grabbing the correct .cpp file that Is present. Is there a way that I can force it to use a .cpp file as well as the .h file?

#include "C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Encoder\Encoder.h"

Since the library is installed, you should probably use:

#include <Encoder.h>

If the .h and .cpp files were in your sketch folder you would use:

#include "Encoder.h"

try this code

#include <Encoder.h>
Encoder myEnc(15, 16);

long oldPosition  = -1000;

void setup() {
  Serial.println(F("Encoder Test:"));

void loop() {
  long newPosition = myEnc.read() >> 1; // my encoder delivers 2 ticks per click
  if (newPosition != oldPosition) {
    oldPosition = newPosition;

does it compile?

Thanks for the replies all, I wanted it to use the specifically installed library and not the "arduino installed" one. What I ended up doing that fixed the issue was adding

#include "C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Encoder\Encoder.cpp"

This looks like it just forced the IDE to not ignore the .cpp file at compile time.

well it especially dumped all the code from that file into your code... so yes it was no longer ignored. But that's not the way to do it. Libraries should be installed where expected

#including .cpp files is a recipe for disaster in multi-file projects.