无法编译 hackrf.c
Cannot compile hackrf.c
我尝试 compile/build 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'
等等...
那我想我应该直接link 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
和 pthread...
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
我该怎么办?
I really don't know how to fix the error above or how to successfully compile the .c file anymore.
你没有遇到问题编译,你遇到了问题linking.
您的 link 失败的原因是 hackrf.c
缺少每个 C
程序都需要的 main()
功能。那是因为它是图书馆的一部分。
通常,您会希望使用项目 provides.
的说明构建整个项目,而不仅仅是一个库
如果您想要构建一个库,那么您应该link它与您程序的其余部分。
我尝试 compile/build 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'
等等...
那我想我应该直接link 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
和 pthread...
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我该怎么办?
I really don't know how to fix the error above or how to successfully compile the .c file anymore.
你没有遇到问题编译,你遇到了问题linking.
您的 link 失败的原因是 hackrf.c
缺少每个 C
程序都需要的 main()
功能。那是因为它是图书馆的一部分。
通常,您会希望使用项目 provides.
的说明构建整个项目,而不仅仅是一个库如果您想要构建一个库,那么您应该link它与您程序的其余部分。