Thread: gcc: undefined reference for phidgets functions

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    26

    gcc: undefined reference for phidgets functions

    Hi,

    I'm trying to write a simple test program to make some calls to a Phidgets board. I have the test app in a directory and the Phidgets files in a subdirectory. my include in my app looks like

    Code:
    #include "phidget21/phidget21.h"
    and phidget21.h is in the subdirectory with the functions I call defined. When I go to make my program I get several undefined references.

    Code:
    root@desktop:/home/Coro#  gcc -o test test.c -I${PWD}/phidget21
    /tmp/cc68a4cW.o: In function `main':
    test.c:(.text+0xed): undefined reference to `CPhidgetInterfaceKit_create'
    test.c:(.text+0x100): undefined reference to `CPhidget_open'
    test.c:(.text+0x114): undefined reference to `CPhidget_getDeviceStatus'
    test.c:(.text+0x139): undefined reference to `CPhidgetInterfaceKit_getSensorValue'
    test.c:(.text+0x153): undefined reference to `CPhidgetInterfaceKit_getSensorValue'
    test.c:(.text+0x16d): undefined reference to `CPhidgetInterfaceKit_getSensorValue'
    test.c:(.text+0x187): undefined reference to `CPhidgetInterfaceKit_getSensorValue'
    test.c:(.text+0x1a1): undefined reference to `CPhidgetInterfaceKit_getSensorValue'
    /tmp/cc68a4cW.o:test.c:(.text+0x1bb): more undefined references to `CPhidgetInterfaceKit_getSensorValue' follow
    collect2: ld returned 1 exit status
    As I said earlier, all these functions are defined the phidget21.h which is located in the subdirectory...

    Thanks for looking,
    Chris

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    You need to compile phidget21.c and then link the resulting object file with test.o, eg:

    Code:
    root@desktop:/home/Coro#  gcc -o test.o test.c -I${PWD}/phidget21
    root@desktop:/home/Coro#  gcc -o phidget21.o phidget21.c -I${PWD}/phidget21
    root@desktop:/home/Coro#  gcc -o test test.o phidget21.o

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference to functions, that CAN be found
    By Carola in forum C++ Programming
    Replies: 8
    Last Post: 08-27-2009, 05:59 AM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. MinGW Linking GUI Program
    By Tonto in forum Tech Board
    Replies: 19
    Last Post: 08-23-2006, 03:28 PM
  4. Strange/false errors
    By Ganoosh in forum Windows Programming
    Replies: 8
    Last Post: 10-20-2005, 04:54 PM
  5. Cygwin/gcc Incompatibility With Winsock2.h
    By maththeorylvr in forum Networking/Device Communication
    Replies: 2
    Last Post: 06-17-2005, 11:23 PM