如何在ubuntu上使用Makefile编译C程序?

时间:2018-08-04 17:22:19

标签: c linux ubuntu makefile compilation

我正在尝试编译一些我在github上找到的程序。存储库位于以下URL: [在此处输入链接说明] [1]

https://github.com/iagox86/nbtool

我对C程序知之甚少,但是当我尝试通过以下命令使用GCC时,会收到错误消息。 我尝试过的命令是:

gcc -o dnslogger dnslogger.c

我收到以下错误:

/tmp/ccLRFQbp.o: In function `dns_callback':
dnslogger.c:(.text+0x51): undefined reference to `dns_create_from_packet'
dnslogger.c:(.text+0x5f): undefined reference to `dns_create'
dnslogger.c:(.text+0x10e): undefined reference to `dns_add_question'
dnslogger.c:(.text+0x179): undefined reference to `dns_add_answer_A'
dnslogger.c:(.text+0x1dc): undefined reference to `dns_add_answer_AAAA'
dnslogger.c:(.text+0x214): undefined reference to `dns_to_packet'
dnslogger.c:(.text+0x236): undefined reference to `udp_send'
dnslogger.c:(.text+0x260): undefined reference to `dns_create_error_string'
dnslogger.c:(.text+0x282): undefined reference to `udp_send'
dnslogger.c:(.text+0x28e): undefined reference to `safe_free'
dnslogger.c:(.text+0x29a): undefined reference to `dns_destroy'
dnslogger.c:(.text+0x2a6): undefined reference to `dns_destroy'
/tmp/ccLRFQbp.o: In function `dns_poll':
dnslogger.c:(.text+0x2d7): undefined reference to `select_group_create'
dnslogger.c:(.text+0x304): undefined reference to `select_group_add_socket'
dnslogger.c:(.text+0x321): undefined reference to `select_set_recv'
dnslogger.c:(.text+0x336): undefined reference to `select_group_do_select'
/tmp/ccLRFQbp.o: In function `cleanup':
dnslogger.c:(.text+0x36b): undefined reference to `select_group_destroy'
dnslogger.c:(.text+0x37a): undefined reference to `safe_free'
dnslogger.c:(.text+0x384): undefined reference to `print_memory'
/tmp/ccLRFQbp.o: In function `main':
dnslogger.c:(.text+0x6ed): undefined reference to `safe_malloc_internal'
dnslogger.c:(.text+0x718): undefined reference to `winsock_initialize'
dnslogger.c:(.text+0x934): undefined reference to `dns_do_test'
dnslogger.c:(.text+0xaab): undefined reference to `udp_create_socket'
dnslogger.c:(.text+0xb5f): undefined reference to `drop_privileges'
collect2: error: ld returned 1 exit status

我的存储库中有一个Makefile文件,我怀疑它是用来编译程序的,但是我不确定在ubuntu上使用的确切命令,我已经尝试了一些命令,但是在使用提供的命令时收到错误文件。 生成文件位于此处:

https://github.com/iagox86/nbtool/blob/master/Makefile

如何从ubuntu命令行编译这些程序?

预先感谢

1 个答案:

答案 0 :(得分:2)

只需运行make

git clone https://github.com/iagox86/nbtool
cd nbtool
make

您需要一些程序来编译所有内容(样本)。 (make会在您的系统上缺少它们时进行投诉)

如果您对Makefile本身更感兴趣,请使用注释中的链接或阅读特定的文档,例如Gnu Make (我选择了Gnu Make,因为标签明确指定了ubuntu)