链接protobuf库的问题 [英] problems with linking protobuf library

查看:41
本文介绍了链接protobuf库的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对makefile不熟悉,这是我的makefile

I am not familiar with makefile, here is my makefile

CC = gcc

TARGET = sample_client sample_server

CFLAGS += -g -I/usr/include
LDFLAGS += -g -lprotobuf-c -L/usr/lib

all:    $(TARGET)

$(TARGET):  lsp.o lspmessage.pb-c.o

%.o:    %.c
    $(CC) -c $(CFLAGS) $< -o $@

clean:
    rm -f *.o 
    rm -f $(TARGET)

当我运行 make -f Make 时,出现这些错误.

when I run make -f Make, I get these errors.

**@**:./$ make -f Makefile
gcc -g -I/usr/include  -g -lprotobuf-c -L/usr/lib  sample_client.c lsp.o lspmessage.pb-c.o   -o sample_client
lspmessage.pb-c.o: In function `lspmessage__get_packed_size':
./lspmessage.pb-c.c:19: undefined reference to `protobuf_c_message_get_packed_size'
lspmessage.pb-c.o: In function `lspmessage__pack':
./lspmessage.pb-c.c:26: undefined reference to `protobuf_c_message_pack'
lspmessage.pb-c.o: In function `lspmessage__pack_to_buffer':
./lspmessage.pb-c.c:33: undefined reference to `protobuf_c_message_pack_to_buffer'
lspmessage.pb-c.o: In function `lspmessage__unpack':
/home/**/Downloads/CSCE662/HW/skeleton-code/lspmessage.pb-c.c:41: undefined reference to `protobuf_c_message_unpack'
lspmessage.pb-c.o: In function `lspmessage__free_unpacked':
./lspmessage.pb-c.c:50: undefined reference to `protobuf_c_message_free_unpacked'
collect2: error: ld returned 1 exit status
make: *** [sample_client] Error 1

我不知道原因.谢谢!

推荐答案

C 链接器的工作原理是只搜索文件之后的库.

The C linker works so that only libraries that come after a file are searched.

尝试像这样重新排列该行:

Try reordering the line like this:

<代码>gcc -g -I/usr/include -g sample_client.c lsp.o lspmessage.pb-c.o -o sample_client -L/usr/lib -lprotobuf-c

您可以先从命令行运行它,看看问题是否已解决.之后,要修复您的 Makefile,请参阅此问题 How to use LDFLAGS in makefile.

You can first run that from the command line to see if the problem is fixed. After that, to fix your Makefile, see this question How to use LDFLAGS in makefile.

这篇关于链接protobuf库的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆