- 論壇徽章:
- 0
|
本帖最后由 冬天的落陽(yáng) 于 2012-05-03 16:02 編輯
你點(diǎn)進(jìn)來(lái)看了?謝謝圍觀,但是事情不像你想象的那么簡(jiǎn)單。。。。。
簡(jiǎn)單描述:鏈接時(shí)已經(jīng)指定了庫(kù)文件路徑,顯然編譯器也能找到該文件(不然它會(huì)說(shuō)的),但是仍然提示:usb2ram.c: (.text+0x710): undefined reference to `usb_init' 等信息。
詳細(xì)描述(為了不浪費(fèi)大家猜測(cè)的時(shí)間,寫的很詳細(xì)。。。。):
我想在一塊s3c2410的開(kāi)發(fā)板上,做一個(gè)簡(jiǎn)單的應(yīng)用程序通過(guò)usb接口從主機(jī)(ubuntu,2.6.32)下載文件。于是網(wǎng)上找到了usb2ram,很小巧的程序源碼,不過(guò)需要libusb支持。
初步測(cè)試,在主機(jī)上運(yùn)行編譯、配合usb-vivi使用,都OK。
接下來(lái)我想把代碼移植到開(kāi)發(fā)板上。沒(méi)有改動(dòng)代碼,先交叉編譯看看能否通過(guò)。
1.交叉編譯libusb--OK。
官網(wǎng)下載libusb1.0,用4.4.3的交叉編譯器進(jìn)行交叉編譯,OK,無(wú)問(wèn)題。
生成的靜態(tài)和動(dòng)態(tài)庫(kù):libusb-1.0.a libusb-1.0.la libusb-1.0.so libusb-1.0.so.0 libusb-1.0.so.0.1.0 ,都拷貝到交叉編譯工具的lib中了。
頭文件:libusb.h
注意,該源碼中不含usb.h
2.交叉編譯usb2ram代碼。為了大家看的方便,我就不貼makefile了,把終端里的最終命令寫出來(lái):
# /home/username/toolschain/4.4.3/bin/arm-linux-gcc -static -o a.out usb2ram.c -I/usr/include -lm -lusb-1.0
/tmp/ccQa2wq4.o: In function `find_qt2410_device':
usb2ram.c: (.text+0x1f0): undefined reference to `usb_busses'
/tmp/ccQa2wq4.o: In function `qt2410_send_file':
usb2ram.c: (.text+0x4ac): undefined reference to `usb_bulk_write'
/tmp/ccQa2wq4.o: In function `main':
usb2ram.c: (.text+0x710): undefined reference to `usb_init'
usb2ram.c: (.text+0x714): undefined reference to `usb_find_busses'
usb2ram.c: (.text+0x72c): undefined reference to `usb_find_devices'
usb2ram.c: (.text+0x7c : undefined reference to `usb_open'
usb2ram.c: (.text+0x7ec): undefined reference to `usb_strerror'
usb2ram.c: (.text+0x81 : undefined reference to `usb_claim_interface'
usb2ram.c: (.text+0x82c): undefined reference to `usb_strerror'
collect2: ld returned 1 exit status
大家可以看到,我在靜態(tài)鏈接的時(shí)候已經(jīng)注意了-l的順序了。。。。
有人說(shuō)你試試動(dòng)態(tài)鏈接?唉,我都搞了大半天了,能沒(méi)試過(guò)嗎:
# /home/username/arm-kernel/toolschain/4.4.3/bin/arm-linux-gcc -o a.out usb2ram.c -I/usr/include -lm -lusb-1.0
/tmp/ccAHTRjz.o: In function `find_qt2410_device':
usb2ram.c: (.text+0x1f0): undefined reference to `usb_busses'
/tmp/ccAHTRjz.o: In function `qt2410_send_file':
usb2ram.c: (.text+0x4ac): undefined reference to `usb_bulk_write'
/tmp/ccAHTRjz.o: In function `main':
usb2ram.c: (.text+0x710): undefined reference to `usb_init'
usb2ram.c: (.text+0x714): undefined reference to `usb_find_busses'
usb2ram.c: (.text+0x72c): undefined reference to `usb_find_devices'
usb2ram.c: (.text+0x7c : undefined reference to `usb_open'
usb2ram.c: (.text+0x7ec): undefined reference to `usb_strerror'
usb2ram.c: (.text+0x81 : undefined reference to `usb_claim_interface'
usb2ram.c: (.text+0x82c): undefined reference to `usb_strerror'
collect2: ld returned 1 exit status
出錯(cuò)信息一樣一樣兒的。。。。
從出錯(cuò)信息推斷,肯定找到對(duì)應(yīng)的庫(kù)文件了,但是就是找不到函數(shù)。我查看了庫(kù)文件:
$ file libusb-1.0.a libusb-1.0.so.0.1.0
libusb-1.0.a: current ar archive
libusb-1.0.so.0.1.0: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, not stripped
沒(méi)看出什么問(wèn)題來(lái)。
其間還嘗試了4.3.2的交叉編譯器,一樣的問(wèn)題。
強(qiáng)調(diào)一下,該代碼在主機(jī)上編譯、使用都很OK。
那么,高手們啊,問(wèn)題可能在哪里呢?
提供usb2ram源代碼,有額外興趣的話也可以下載:
usb2ram.tar.gz
(9 KB, 下載次數(shù): 48)
2012-05-03 15:58 上傳
點(diǎn)擊文件名下載附件
usb2ram
|
|