0

I'm trying to compile this code on Ubuntu 12.04 (can't upgrade) as a base for another program I need to do, however, I think I've spent too much time in the PHP/Python world and this error is driving me insane. I've looked everywhere, and found this question on SO with almost the same error, but unfortunately no answers.

I've installed OpenKinect/libfreenect from source per the instructions on this page, also installed libpng1.2 and ran the freenect examples just fine. I've also tried moving the CFLAGS and LDFLAGS around but no luck yet.

Relevant info:

$ make
cc -O3 -I/usr/local/include/libfreenect -c kinect.c
cc -O3 -I/usr/local/include/libfreenect -c image.c
cc -O3 -I/usr/local/include/libfreenect -c buffer.c
cc -O3 -I/usr/local/include/libfreenect -lpng -lfreenect -o kinect-depth-ascii kinect.o image.o buffer.o kinect-depth-ascii.c
/tmp/ccsUHika.o: In function `draw_depth_image':
kinect-depth-ascii.c:(.text+0x131): undefined reference to `Image_get_pixel'
kinect.o: In function `kinect_capture_depth_image':
kinect.c:(.text+0x55): undefined reference to `Image_set_pixel'
kinect.o: In function `kinect_initialize':
kinect.c:(.text+0x15c): undefined reference to `freenect_init'
kinect.c:(.text+0x179): undefined reference to `freenect_select_subdevices'
kinect.c:(.text+0x186): undefined reference to `freenect_num_devices'
kinect.c:(.text+0x1ab): undefined reference to `freenect_open_device'
kinect.c:(.text+0x1e6): undefined reference to `freenect_set_led'
kinect.c:(.text+0x1fb): undefined reference to `freenect_set_depth_callback'
kinect.c:(.text+0x217): undefined reference to `freenect_find_depth_mode'
kinect.c:(.text+0x257): undefined reference to `freenect_set_depth_mode'
kinect.c:(.text+0x264): undefined reference to `freenect_start_depth'
kinect.c:(.text+0x2de): undefined reference to `freenect_shutdown'
kinect.o: In function `kinect_process_events':
kinect.c:(.text+0x3a3): undefined reference to `freenect_process_events'
kinect.o: In function `kinect_shutdown':
kinect.c:(.text+0x3f7): undefined reference to `freenect_stop_depth'
kinect.c:(.text+0x40c): undefined reference to `freenect_set_led'
kinect.c:(.text+0x419): undefined reference to `freenect_close_device'
kinect.c:(.text+0x426): undefined reference to `freenect_shutdown'
image.o: In function `Image_get_png_write_data':
image.c:(.text+0x2b): undefined reference to `png_get_io_ptr'
image.o: In function `Image_write_png_internal':
image.c:(.text+0x119): undefined reference to `png_create_write_struct'
image.c:(.text+0x12d): undefined reference to `png_create_info_struct'
image.c:(.text+0x16d): undefined reference to `png_init_io'
image.c:(.text+0x1be): undefined reference to `png_set_IHDR'
image.c:(.text+0x1d2): undefined reference to `png_write_info'
image.c:(.text+0x260): undefined reference to `png_write_end'
image.c:(.text+0x270): undefined reference to `png_destroy_info_struct'
image.c:(.text+0x285): undefined reference to `png_destroy_write_struct'
image.c:(.text+0x2a8): undefined reference to `png_write_row'
image.c:(.text+0x2e4): undefined reference to `png_set_write_fn'
image.c:(.text+0x2fd): undefined reference to `png_destroy_info_struct'
image.c:(.text+0x30f): undefined reference to `png_destroy_write_struct'
image.c:(.text+0x32d): undefined reference to `png_destroy_write_struct'
image.o: In function `Image_downsample':
image.c:(.text+0x490): undefined reference to `lround'
image.c:(.text+0x4c9): undefined reference to `lround'
collect2: ld devolvió el estado de salida 1
make: *** [kinect-depth-ascii] Error 1

$ cc --version
cc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
Esto es software libre; vea el código para las condiciones de copia.  NO hay
garantía; ni siquiera para MERCANTIBILIDAD o IDONEIDAD PARA UN PROPÓSITO EN
PARTICULAR

$ ls -l /usr/local/lib/
total 164
drwxr-xr-x 2 root root   4096 jul  6 13:36 fakenect
-rw-r--r-- 1 root root  64566 jul  6 13:36 libfreenect.a
lrwxrwxrwx 1 root root     18 jul  6 13:36 libfreenect.so -> libfreenect.so.0.4
lrwxrwxrwx 1 root root     20 jul  6 13:36 libfreenect.so.0.4 -> libfreenect.so.0.4.3
-rw-r--r-- 1 root root  53522 jul  6 13:36 libfreenect.so.0.4.3
-rw-r--r-- 1 root root   9132 jul  6 13:36 libfreenect_sync.a
lrwxrwxrwx 1 root root     23 jul  6 13:36 libfreenect_sync.so -> libfreenect_sync.so.0.4
lrwxrwxrwx 1 root root     25 jul  6 13:36 libfreenect_sync.so.0.4 -> libfreenect_sync.so.0.4.3
-rw-r--r-- 1 root root  17474 jul  6 13:36 libfreenect_sync.so.0.4.3
drwxr-xr-x 2 root root   4096 jul  6 13:36 pkgconfig
drwxrwsr-x 4 root staff  4096 jun 28 21:14 python2.7

$ ls -l /usr/local/include/libfreenect
total 48
-rw-r--r-- 1 root root 27024 jul  6 13:35 libfreenect.h
-rw-r--r-- 1 root root  9380 jul  6 13:35 libfreenect.hpp
-rw-r--r-- 1 root root  3587 jul  6 13:35 libfreenect_registration.h
-rw-r--r-- 1 root root  3995 jul  6 13:35 libfreenect_sync.h

Makefile (the same as the Github repo):

all: kinect-depth-ascii kinect-depth-png

CFLAGS=-O3 -I/usr/local/include/libfreenect
LDFLAGS=-lpng -lfreenect

kinect-depth-ascii: kinect.o image.o buffer.o kinect-depth-ascii.c
    cc $(CFLAGS) $(LDFLAGS) -o $@ $^

kinect-depth-png: kinect.o image.o buffer.o kinect-depth-png.c
    cc $(CFLAGS) $(LDFLAGS) -o $@ $^

kinect.o: kinect.h kinect.c
    cc $(CFLAGS) -c kinect.c

image.o: image.h image.c
    cc $(CFLAGS) -c image.c

buffer.o: buffer.h buffer.c
    cc $(CFLAGS) -c buffer.c

clean:
    rm -f *.o kinect-depth-ascii kinect-depth-png

Can anyone please shed some light as to what is wrong here? (Additional question: What does the "$^" at the end of kinect-depth-ascii and kinect-depth-png lines do?)

Thank you very much in advance.

Community
  • 1
  • 1
kenshin23
  • 129
  • 13
  • `$^` and `$@` are both GNU make [automatic variables](http://www.gnu.org/software/make/manual/make.html#Automatic-Variables). – Etan Reisner Sep 01 '14 at 03:02
  • Inlcuding `.c` files as prerequisites on the `kinect-depth-ascii` and `kinect-depth-png` lines is decidedly odd and doesn't seem like it would work to me. All told this makefile is not very well written. I think adding `-L/usr/local/lib` to the start of the `LDFLAGS` line might help with some of the errors though. – Etan Reisner Sep 01 '14 at 03:04
  • @Etan-Reisner Thanks for the info and the suggestion. I've tried adding that to LDFLAGS and running make clean && make, but the error remains. As far as I know, the linker flags go after the output file, right? I mean, they should be called at the end of the cc lines, not right at the beginning. Please correct me if I'm wrong. – kenshin23 Sep 03 '14 at 04:22
  • `-L` flags need to be before (I believe) any `-l` flags that need that path. `-l` flags need to come after any objects that use symbols from them. And actually, that's probably part of the problem, your link lines don't do that. Try re-ordering them and/or dropping your rules and using the built-in ones (which means `-L` in `LDFLAGS` `-l` in `LDLIBS`). – Etan Reisner Sep 03 '14 at 11:14

1 Answers1

0

So, to answer my own question, thanks to Etan Reisner's advice from the comments, I've committed the changes necessary to compile this project, right here: https://github.com/kenshin23/kinect/commit/d3186db346c7d9e534b6eed9d76547a93ed12e66

The working Makefile is:

all: kinect-depth-ascii kinect-depth-png

CFLAGS=-O3
LDFLAGS=-I/usr/local/include/libfreenect -I/usr/include/libusb-1.0 -I/usr/include/libpng12
LDLIBS=-L/usr/local/lib -lpng12 -lfreenect

kinect-depth-ascii: image.o buffer.o kinect.o kinect-depth-ascii.c
    cc $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)

kinect-depth-png: image.o buffer.o kinect.o kinect-depth-png.c
    cc $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)

kinect.o: kinect.h kinect.c
    cc $(CFLAGS) -c kinect.c $(LDFLAGS) $(LDLIBS)

image.o: image.h image.c
    cc $(CFLAGS) -c image.c $(LDFLAGS) $(LDLIBS)

buffer.o: buffer.h buffer.c
    cc $(CFLAGS) -c buffer.c $(LDFLAGS) $(LDLIBS)

clean:
    rm -f *.o kinect-depth-ascii kinect-depth-png

(It could probably use some cleaning up, but now it works.)

kenshin23
  • 129
  • 13