我嘗試編譯/構建 hackrf.c,因為我在另一個代碼中使用該庫,我將 hackrf.h 放在與我正在構建 hackrf.c 的目錄相同的目錄中......
https://github.com/greatscottgadgets/hackrf/tree/master/host/libhackrf/src
理想情況下,它應該這樣做,但是我在終端中收到了這些錯誤:
choza@chozaUbuntu:~/Documents/workspace_c$ gcc hackrf.c
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text 0x24): undefined reference to `main'
/usr/bin/ld: /tmp/ccrRkrH1.o: in function `cancel_transfers':
hackrf.c:(.text 0x139): undefined reference to `libusb_cancel_transfer'
/usr/bin/ld: /tmp/ccrRkrH1.o: in function `free_transfers':
hackrf.c:(.text 0x25b): undefined reference to `libusb_free_transfer'
/usr/bin/ld: /tmp/ccrRkrH1.o: in function `allocate_transfers':
hackrf.c:(.text 0x337): undefined reference to `libusb_alloc_transfer'
/usr/bin/ld: /tmp/ccrRkrH1.o: in function `prepare_transfers':
hackrf.c:(.text 0x484): undefined reference to `libusb_submit_transfer'
/usr/bin/ld: /tmp/ccrRkrH1.o: in function `detach_kernel_drivers':
hackrf.c:(.text 0x4ee): undefined reference to `libusb_get_device'
/usr/bin/ld: hackrf.c:(.text 0x505): undefined reference to `libusb_get_active_config_descriptor'
/usr/bin/ld: hackrf.c:(.text 0x53b): undefined reference to `libusb_free_config_descriptor'
/usr/bin/ld: hackrf.c:(.text 0x555): undefined reference to `libusb_kernel_driver_active'
/usr/bin/ld: hackrf.c:(.text 0x592): undefined reference to `libusb_detach_kernel_driver'
等等...
然后我想我應該直接鏈接 libusb ......但我明白了:
choza@chozaUbuntu:~/Documents/workspace_c$ gcc hackrf.c -lusb-1.0
/usr/bin/ld: /tmp/ccfIzbqD.o: undefined reference to symbol 'pthread_join@@GLIBC_2.2.5'
/usr/bin/ld: /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
和執行緒...
choza@chozaUbuntu:~/Documents/workspace_c$ gcc hackrf.c -lusb-1.0 -pthread
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text 0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status
我真的不知道如何修復上面的錯誤或如何成功編譯 .c 檔案了。
我在 Ubuntu 20.04 中使用 VS Code。
我該怎么辦?
uj5u.com熱心網友回復:
我真的不知道如何修復上面的錯誤或如何成功編譯 .c 檔案了。
你沒有編譯問題,你有問題鏈接。
您的鏈接失敗的原因是hackrf.c缺少main()每個C程式都需要的功能。那是因為它是圖書館的一部分。
通常,您需要使用專案提供的說明來構建整個專案,而不僅僅是一個庫。
如果您確實想構建一個庫,那么您應該將它與程式的其余部分鏈接起來。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/445120.html
下一篇:獲取桌面上運行的程式
