gpt4 book ai didi

c - 使用 libfreenect 编译代码时出现链接器错误

转载 作者:行者123 更新时间:2023-11-30 17:29:29 25 4
gpt4 key购买 nike

我正在尝试在 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-深度-ascii 和 kinect-深度-png 行末尾的“$^”有什么作用?)

提前非常感谢您。

最佳答案

因此,为了回答我自己的问题,感谢 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

(可能需要进行一些清理,但现在可以了。)

关于c - 使用 libfreenect 编译代码时出现链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25598284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com