Apache Avro C安装 [英] Apache Avro C Installation

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

问题描述

我正在开发一个项目,并且正在使用Apache Avro.我已经下载了Apache Avro for C,并且按照提供的说明进行了安装,以便将其安装在系统上(Ubuntu Linux v14.04).安装后,我在/include 目录下有一些头文件,在/lib 目录下有一些库.所有这些都是从Apache Avro安装的.

I am working on a project and I am using Apache Avro. I have downloaded Apache Avro for C and I followed the instructions provided in order to install it on my system (Ubuntu Linux v14.04). After the installation, I have some header files under the /include directory and some libraries under /lib directory. All of those are the ones that were installed from Apache Avro.

至此,我已经创建了如下的C源文件:

At this point, I have created my C source files which are as follows:

1)socket_client.h:

1) socket_client.h :

#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "avro.h"
#include <errno.h>
#include <stdint.h>

#ifndef SOCKET_CLIENT_H_
#define SOCKET_CLIENT_H_

void init_schema(void);

int client_execution_connect(char* ip_addr, int port, char* type);

#endif /* SOCKET_CLIENT_H_ */

2)socket_client.c:

2) socket_client.c :

#include <stdio.h>
#include "socket_client.h"

avro_schema_t bigpeer_schema;
void init_schema(void)
{
    if( avro_schema_from_json_literal(BIG_PEER_SCHEMA, &bigpeer_schema) )
    {
        printf("Unable to parse big_peer schema");
        exit(EXIT_FAILURE);
    }
}
int client_execution_connect(char* ip_addr, int port, char* type)
{
    ...
}

和一个测试主文件.另外,我创建了以下makefile来编译我的代码:

and a test main file. Also, I have created the following makefile to compile my code:

CC=gcc
CFLAGS=-c -Wall
LDFLAGS=
SOURCES=test_main.c socket_client.c
OBJECTS=$(SOURCES:.c=.o)
EXECUTABLE=avro_test
INC_PATH=/include/avro/

INC=-I/include
LIB=-L/lib

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
    $(CC) $(LDFLAGS) $(LIB) $(OBJECTS) -o $@

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

clean:
    rm -rf *.o avro_test

但是,当我尝试进行申请时,会得到以下信息:

But, when I try to make my application, I get the following:

nick@rethimno:~/Downloads/AvroClient$ make
gcc -I/include -c -Wall test_main.c -o test_main.o
test_main.c: In function ‘main’:
test_main.c:22:6: warning: unused variable ‘port’ [-Wunused-variable]
  int port = atoi(argv[2]);
      ^
test_main.c:15:8: warning: unused variable ‘type’ [-Wunused-variable]
   char* type = "db_node";
        ^
gcc -I/include -c -Wall socket_client.c -o socket_client.o
gcc  -L/lib test_main.o socket_client.o -o avro_test
socket_client.o: In function `init_schema':
socket_client.c:(.text+0x14): undefined reference to `avro_schema_from_json_length'
collect2: error: ld returned 1 exit status
make: *** [avro_test] Error 1

我做错了什么?我不确定Apache Avro的库是否正确加载.

What am I doing wrong? I am not quite certain if the libraries of Apache Avro are loaded properly.

谢谢你,尼克

推荐答案

您包括了Avro标头,但没有将最终的可执行文件链接到Avro库.假设您在 lib 目录(其中 *.so 是共享目录)中具有 libavro.so libavro.a 库,而 *.a 是静态库),则需要更改Makefile的这一行:

You are including the Avro headers, but you aren't linking your final executable against the Avro libraries. Assuming you have libavro.so or libavro.a in the lib directory (where *.so is a shared library, and *.a is a static library), you will want to change this line of your Makefile:

LDFLAGS = -lavro

请注意,如果库二进制文件被称为 libavro.so libavro.a 以外的名称,则需要更改 -lavro 值进行匹配.另请注意,某些软件包可能包含多个您需要链接的共享库.我对Apache Avro不够熟悉,无法说出是这种情况.您通常只需要查看并查看 lib 目录中的内容.

Note that, if the library binary is called something other than libavro.so or libavro.a, you'll need to change the -lavro value to match. Also note that certain packages can contain more than one shared library you will need to link against. I am not familiar enough with Apache Avro to say whether or not this is the case; you will mostly just need to look and see what is inside your lib directory.

您可以在 GCC文档中了解有关链接到库的更多信息.

You can more information about linking to libraries in the GCC documentation.

这篇关于Apache Avro C安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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