PDA

View Full Version : Problems linking to libphidget21



bidi
01-30-2007, 03:40 PM
I'm trying to develop a simple program to control a 1001 Phidget board but whenever I try to compile the software the linker complains about undefined reference to the functions used. For example, if I try to compile the following program:

#include <phidget21.h>
int main (int argc, char* argv[])
{
int result;
CPhidgetServoHandle Servo = 0;
CPhidgetServo_create (&Servo);

CPhidgetServo_close (Servo);
CPhidget_delete (Servo);
return 0;
}

I get the following errors:

test2.c:(.text+0x1f): undefined reference to 'CPhidgetServo_create'
test2.c:(.text+0x2a): undefined reference to 'CPhidgetServo_close'
test2.c:(.text+0x35): undefined reference to 'CPhidget_delete'
collect2: ld returned 1 exit status

So then I tried compiling with

gcc -l phidget21 test.c
and get these errors

test2.c:(.text+0x2a): undefined reference to `CPhidgetServo_close'
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/libphidget21.so: undefined reference to `sqrt'
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/libphidget21.so: undefined reference to `cos'
collect2: ld returned 1 exit status

I'm trying to compile this using GCC 4.1.2 under Debian GNU/Linux with Linux kernel version 2.6.18. I've compiled quite a bit of code under this box and never had these problems, they all seem to stem from libphidget21.

Thanks

bidi
01-30-2007, 04:37 PM
Going further into the problem, I actually figured out it's deeper than just libphidget21. I still can't figure out what is causing it, so any help would be great.

Thanks

bidi
01-30-2007, 05:07 PM
I actually asked on another forum and got the answer! What was happening is that since libphidget21 needs math.h I also needed to pass the compiler the -lm option. So the final command line option looks like:

gcc -lphidget21 -lm <c-file>

Alex
01-31-2007, 09:11 AM
Great to hear you found the answer:) I was asking around because I don't have that much experience in Linux, but you beat me to it. Thanks for putting up the answer for others.

What sort of project are you working on?