LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 09-10-2009, 09:06 AM   #1
chris24300
Member
 
Registered: Jul 2009
Posts: 58

Rep: Reputation: 15
Makefile: including a subdirectory filled with headers and srcs


Hi, I'm not familiar with makefile at all and I need to compile some test code to communicate with a Phidgets board. I know of the -I option so I've been trying to get that to work but I have no luck. In my directory I have the phidgets folder that contains the headers and sources to their calls. I tried looking at makefile templates but they were far too confusing. Here is my makefile

Code:
# Phidgets makefile

all: test

CC 	= gcc

INCL	= /phidget21

test: test.c
	$(CC) test.c -o test -I$(INCL) 

//////////////////////////////////////////
                 OUTPUT
//////////////////////////////////////////

gcc test.c -o test -I/phidget21 
/tmp/ccMlFdVS.o: In function `main':
test.c:(.text+0xee): undefined reference to `CPhidgetInterfaceKit_create'
test.c:(.text+0x103): undefined reference to `CPhidget_open'
test.c:(.text+0x119): undefined reference to `CPhidget_getDeviceStatus'
test.c:(.text+0x141): undefined reference to `CPhidgetInterfaceKit_getSensorValue'
test.c:(.text+0x15e): undefined reference to `CPhidgetInterfaceKit_getSensorValue'
test.c:(.text+0x17b): undefined reference to `CPhidgetInterfaceKit_getSensorValue'
test.c:(.text+0x198): undefined reference to `CPhidgetInterfaceKit_getSensorValue'
test.c:(.text+0x1b5): undefined reference to `CPhidgetInterfaceKit_getSensorValue'
/tmp/ccMlFdVS.o:test.c:(.text+0x1d2): more undefined references to `CPhidgetInterfaceKit_getSensorValue' follow
collect2: ld returned 1 exit status
make: *** [test] Error 1

Thanks for all the help!
Chris
 
Old 09-10-2009, 09:10 AM   #2
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
The -l or -L options are linker arguments, as well as (or rather than) compiler arguments.

If you want to tell the linker to include a shared (object) library, use the lowercase -l with the path to/name of the library. To tell the linker to include a directory full of libraries in its search path, use the capital -L with the path to the directory.

Examples:

-lsomelib.so
-L/usr/lib

Best success,
Sasha
 
Old 09-10-2009, 09:56 AM   #3
chris24300
Member
 
Registered: Jul 2009
Posts: 58

Original Poster
Rep: Reputation: 15
Thanks for the response GrapefruiTgirl. The folder looks like it was included but I still get the same output. I don't understand why I still get an undefined reference, the files are clearly in the phidgets directory

Code:
 ls ./phidget21/
clog.c                       cphidgetencoder.o       cphidgetmanager.o            cphidgettextlcd.c       cusblinux.c      pdict-impl.h
clog.h                       cphidgetgps.c           cphidgetmotorcontrol.c       cphidgettextlcd.h       cusblinux.o      pdict.o
clog.o                       cphidgetgps.h           cphidgetmotorcontrol.h       cphidgettextlcd.o       cusbmac.c        pdictserver.c
cphidgetaccelerometer.c      cphidgetgps.o           cphidgetmotorcontrol.o       cphidgettextled.c       cusbwindows.c    pdictserver.h
cphidgetaccelerometer.h      cphidgetgyroscope.c     cphidget.o                   cphidgettextled.h       dns_sd.h         phidget21.c
cphidgetaccelerometer.o      cphidgetgyroscope.h     cphidgetphsensor.c           cphidgettextled.o       examples         phidget21.h
cphidgetadvancedservo.c      cphidgetgyroscope.o     cphidgetphsensor.h           cphidgetweightsensor.c  hotplug          phidget21int.h
cphidgetadvancedservo.h      cphidget.h              cphidgetphsensor.o           cphidgetweightsensor.h  Java             phidget21.o
cphidgetadvancedservo.o      cphidgetinterfacekit.c  cphidgetrfid.c               cphidgetweightsensor.o  libphidget21.a   stdafx.c
cphidgetattr.h               cphidgetinterfacekit.h  cphidgetrfid.h               csocketevents.c         libphidget21.so  stdafx.h
cphidget.c                   cphidgetinterfacekit.o  cphidgetrfid.o               csocketevents.h         libusb           udev
cphidgetconstants.c          cphidgetled.c           cphidgetservo.c              csocketevents.o         Makefile         utils
cphidgetconstants.h          cphidgetled.h           cphidgetservo.h              csocket.h               md5.c            zeroconf_avahi.c
cphidgetconstantsinternal.h  cphidgetled.o           cphidgetservo.o              csocketopen.c           md5.h            zeroconf_avahi.o
cphidgetconstants.o          cphidgetlist.c          cphidgetstepper.c            csocketopen.o           md5.o            zeroconf.c
cphidgetdictionary.c         cphidgetlist.h          cphidgetstepper.h            cthread.c               pdict.c          zeroconf.h
cphidgetdictionary.h         cphidgetlist.o          cphidgetstepper.o            cthread.h               pdictclient.c
cphidgetdictionary.o         cphidgetmacros.h        cphidgettemperaturesensor.c  cthread.o               pdictclient.h
cphidgetencoder.c            cphidgetmanager.c       cphidgettemperaturesensor.h  cusbce.c                pdictclient.o
cphidgetencoder.h            cphidgetmanager.h       cphidgettemperaturesensor.o  cusb.h                  pdict.h
 
Old 09-10-2009, 09:58 AM   #4
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
Hmmm.. Did you happen to check that CPhidgetInterfaceKit_getSensorValue is actually defined in one of the header files?

Oh, wait now! Maybe... Just maybe... the way you are doing your INCLUDE there is like:

Code:
gcc test.c -o test -I/phidget21
and:
Code:
INCL	= /phidget21
Both of which are absolute paths. Maybe try using a relative path, or if the folder is right there within the source, just remove the leading slash on the folder name, OR, use the full absolute path, like:

gcc test.c -o test -Iphidget21

or

gcc test.c -o test -I/full/path/to/location/of/phidget21

maybe we just missed an obvious, very simple typo/thinko?

Sasha

PS - my apology too -- earlier, I misread your capital I (as in 'eye') to be an L (as in ELephant) -- lol, fonts are tricky that way at times.

Last edited by GrapefruiTgirl; 09-10-2009 at 10:04 AM.
 
Old 09-10-2009, 10:08 AM   #5
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
Plus, to make it more bulletproof, I would use something like:

gcc test.c -o test -I${PWD}/phidget21

which will translsate to "current-working-directory"/"phidget21"

Sasha

Last edited by GrapefruiTgirl; 09-10-2009 at 10:10 AM.
 
Old 09-10-2009, 11:23 AM   #6
chris24300
Member
 
Registered: Jul 2009
Posts: 58

Original Poster
Rep: Reputation: 15
Nope, still same output...

I'm 100% positive it's defined in there, and I get undefined reference for _create, open, and getdevicestatus which are defined in the source files I looked at. Maybe I should just put the file in the phidgets directory?

Thanks again!
Chris

That didn't work either... Should I post the code from test.c? Maybe theres a format issue or something.

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "phidget21.h"

CPhidgetInterfaceKitHandle ifkit;

int main(int argc, char **argv)
{
    int phidgetIkStatus = 0;
    int input1 = 0;
    int input2 = 0;
    int input4 = 0; // added front sensor
    int input5 = 0; // added front sensor
    int input6 = 0; // added front sensor
    int input7 = 0; // added front sensor
    ////////////////////////////////////////////////

    // attempt to open the phidgets interface kit
    CPhidgetInterfaceKit_create(&ifkit);
    CPhidget_open((CPhidgetHandle)ifkit, -1);
    
    // prepare to read the information from the phidgets interface board
    CPhidget_getDeviceStatus((CPhidgetHandle)ifkit, &phidgetIkStatus);
    
    if (phidgetIkStatus != 0)
    {
	    // read the IR values
        CPhidgetInterfaceKit_getSensorValue(ifkit, 1, &input1);
        CPhidgetInterfaceKit_getSensorValue(ifkit, 2, &input2);
        CPhidgetInterfaceKit_getSensorValue(ifkit, 4, &input4);
        CPhidgetInterfaceKit_getSensorValue(ifkit, 5, &input5);
        CPhidgetInterfaceKit_getSensorValue(ifkit, 6, &input6);
        CPhidgetInterfaceKit_getSensorValue(ifkit, 7, &input7);

         printf("%d\n%d\n%d\n%d\n%d\n%d", input1, input2, input4, input5, input6, input7); fflush(stdout);
    } // if
    
} // main

Last edited by chris24300; 09-10-2009 at 11:30 AM.
 
Old 09-11-2009, 12:12 PM   #7
chris24300
Member
 
Registered: Jul 2009
Posts: 58

Original Poster
Rep: Reputation: 15
I'm still trying to figure this out, can someone tell me why the initial error comes from /tmp/ccKRuoUK.o? I have the header file in the subdirectory and all the functions are defined. Here is the output

Code:
gcc -o test test.c -I${PWD}/phidget21
/tmp/ccKRuoUk.o: In function `main':
test.c:(.text+0xee): undefined reference to `CPhidgetInterfaceKit_create'
test.c:(.text+0x103): undefined reference to `CPhidget_open'
test.c:(.text+0x119): undefined reference to `CPhidget_getDeviceStatus'
test.c:(.text+0x141): undefined reference to `CPhidgetInterfaceKit_getSensorValue'
test.c:(.text+0x15e): undefined reference to `CPhidgetInterfaceKit_getSensorValue'
test.c:(.text+0x17b): undefined reference to `CPhidgetInterfaceKit_getSensorValue'
test.c:(.text+0x198): undefined reference to `CPhidgetInterfaceKit_getSensorValue'
test.c:(.text+0x1b5): undefined reference to `CPhidgetInterfaceKit_getSensorValue'
/tmp/ccKRuoUk.o:test.c:(.text+0x1d2): more undefined references to `CPhidgetInterfaceKit_getSensorValue' follow
collect2: ld returned 1 exit status
 
Old 09-11-2009, 01:00 PM   #8
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
http://gcc.gnu.org/onlinedocs/gcc-3.0.2/cpp_2.html

Review section 2.1 at the above link. After that, make sure that your location of the mysterious header file, is being correctly included as per the directives on that C preprocessor page.

For example, let's say you have SOURCE, which is a folder from which you are executing your gcc command. And inside SOURCE, you have your PHIDGITS folder, which is where this mystery header file is located.

In this case, I think your #include would read:

#include "PHIDGITS/phidgits.h"

See where I'm leading with this?

And conversely, if the file "phidgits.h" is located right there in the same folder as your command is being run (the SOURCE folder) then your #include would be as you have it:

#include "phidgits.h"

Hopefully I'm not repeating something you've already tried earlier -- I'm no C guru by any stretch of the imagination, just trying to eliminate the easy possibilities

Sasha
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
makefile subdirectory target sancho1980 Linux - General 1 08-18-2008 05:25 PM
Getting the fedora srcs and version headers short circut Fedora 2 06-27-2007 04:53 PM
Unable to include headers in Makefile Raphexion Programming 2 11-05-2005 08:00 AM
How to write Makefile in 2.6 for including header files in another dir ? ashbalu Programming 0 10-19-2004 03:45 PM
c++ programming: including headers from external libraries isl01jbe Programming 3 07-20-2004 08:06 AM


All times are GMT -5. The time now is 06:56 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration