我已经在我的ubuntu上安装了libfirmataplus,但我无法用它编译:
g++ -I/usr/local/include/firmataplus/ Servo.cpp -larduino -lfirmataplus -lfirmataplus_servo
不幸的是,错误并非来自我的代码来自库.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
以下是我尝试编译的代码:(摘自示例)
#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;
}
答案 0 :(得分:1)
修正库的顺序:
g++ -I/usr/local/include/firmataplus/ Servo.cpp -larduino -lfirmataplus_servo -lfirmataplus