0
未定义参考我在安装libfirmataplus下载在我的Ubuntu,但我不能用它编译:麻烦编译libfirmataplus
g++ -I/usr/local/include/firmataplus/ Servo.cpp -larduino -lfirmataplus -lfirmataplus_servo
Unforunately错误并非来自从库我的代码UT的.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;
}
这个启动时编译罚款,但遇到错误:./a.out无法打开共享对象文件:没有这样的文件或目录 – jDourlens
@jDourlens那是一个不同的问题。您可能需要设置'LD_LIBRARY_PATH'或其他东西。 –
非常感谢! – jDourlens