使用libfreenect编译代码时链接器错误

时间:2014-09-01 02:56:09

标签: c gcc makefile openkinect

我试图在Ubuntu 12.04上编译this code(无法升级)作为我需要做的其他程序的基础,不过,我想我花了太多钱在PHP / Python世界中的时间,这个错误让我疯狂。我到处寻找,发现this question on SO with almost the same error,但遗憾的是没有答案。

我已根据this page上的说明从源代码安装了OpenKinect / libfreenect,同时安装了libpng1.2并运行了freenect示例。我还尝试过移动CFLAGS和LDFLAGS,但没有运气。

相关信息:

$ 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 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

任何人都可以对这里的错误有所了解吗? (附加问题:" $ ^"在kinect-depth-ascii和kinect-depth-png行的末尾有什么作用?)

非常感谢你。

1 个答案:

答案 0 :(得分:0)

所以,回答我自己的问题,感谢Etan Reisner对评论的建议,我已经提交了编译这个项目所需的更改,就在这里:https://github.com/kenshin23/kinect/commit/d3186db346c7d9e534b6eed9d76547a93ed12e66

工作的Makefile是:

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

(它可能会使用一些清理,但现在它可以正常工作。)