2014-09-01 108 views
0

我想在Ubuntu 12.04上編譯this code作爲另一個程序的基礎,但我認爲我花了太多時間PHP/Python世界和這個錯誤令我瘋狂。我到處尋找,發現this question on SO with almost the same error,但不幸的是沒有答案。用libfreenect編譯代碼時出現鏈接器錯誤

我已經按照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 [email protected] $^ 

kinect-depth-png: kinect.o image.o buffer.o kinect-depth-png.c 
    cc $(CFLAGS) $(LDFLAGS) -o [email protected] $^ 

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行結尾處的「$ ^」是做什麼的?)

非常感謝您提前。

+0

'$ ^'和'$ @'都是GNU使[自動變量(http://www.gnu.org/software /make/manual/make.html#Automatic-Variables)。 – 2014-09-01 03:02:00

+0

在'kinect-depth-ascii'和'kinect-depth-png'這兩行代碼中包含'.c'文件是非常奇怪的,看起來好像不適合我。所有人都告訴這個makefile文件寫得不好。我認爲在'LDFLAGS'行的開頭添加'-L/usr/local/lib'可能會幫助解決一些錯誤。 – 2014-09-01 03:04:40

+0

@ Etan-Reisner感謝您的信息和建議。我已經嘗試將其添加到LDFLAGS並運行make clean && make,但錯誤依然存在。據我所知,鏈接器標誌位於輸出文件之後,對吧?我的意思是,它們應該在cc行結尾處被調用,而不是在開頭。如果我錯了,請糾正我。 – kenshin23 2014-09-03 04:22:49

回答

0

因此,要回答我的問題,這要歸功於從評論伊坦賴斯納的建議,我已經承諾要編譯該項目的變化,就在這裏: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 [email protected] $^ $(LDFLAGS) $(LDLIBS) 

kinect-depth-png: image.o buffer.o kinect.o kinect-depth-png.c 
    cc $(CFLAGS) -o [email protected] $^ $(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 

(它很可能使用一些清理,但現在它的工作原理。)

相關問題