Question

I've downloaded in installed libfirmataplus on my ubuntu but I can't compile with it:

g++ -I/usr/local/include/firmataplus/  Servo.cpp -larduino -lfirmataplus -lfirmataplus_servo 

Unforunately the error doesn't come from my code ut from the library .so

/usr/local/lib/libfirmataplus_servo.so: undefined reference to `Firmata::setPwmPin(unsigned char, short)'
/usr/local/lib/libfirmataplus_servo.so: undefined reference to `Firmata::openPort(char const*, int)'
/usr/local/lib/libfirmataplus_servo.so: undefined reference to `Firmata::openPort(char const*)'
/usr/local/lib/libfirmataplus_servo.so: undefined reference to `Firmata::Firmata()'
/usr/local/lib/libfirmataplus_servo.so: undefined reference to `Firmata::~Firmata()'
/usr/local/lib/libfirmataplus_servo.so: undefined reference to `Firmata::closePort()'
collect2: error: ld returned 1 exit status

Here is the code I try to compile: (taken from example)

#include <iostream>
#include <firmataservo.h>
#include <stdlib.h>

int main(int argc, char** argv) {
  if (argc < 2) {
    fprintf(stderr,"Usage: %s <serial port path> [pin]\n",__FILE__);
    exit(1);
  }
  char* serial = argv[1];
  int pin=2;
  if (argc == 3) {
    pin = atoi(argv[2]);
  }
  ServoFirmata* sf = new ServoFirmata();
  if (sf->openPort(serial) != 0) {
    fprintf(stderr,"sf->openPort(%s) failed: exiting\n",serial);
    sf->destroy();
    exit(2);
  }
  int origPos = sf->getServoPosition(pin);
  for( int i=SF_POS_MIN; i<SF_POS_MAX; i+=10) {
    printf("Setting servo on pin %d to position %d\n",pin,i);
    sf->setServoPosition(pin,i);
    sleep(1);
  }
  printf("Resetting servo on pin %d to position %d\n",pin,origPos);
  sf->setServoPosition(pin,origPos);
  sf->destroy();
  return 0;
}
Was it helpful?

Solution

Fix the order of the libraries:

g++ -I/usr/local/include/firmataplus/ Servo.cpp -larduino -lfirmataplus_servo -lfirmataplus
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top