Apache Avro C Installation

倾然丶 夕夏残阳落幕 提交于 2021-01-29 08:01:43

问题


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.

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

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 :

#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)
{
    ...
}

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

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

Thank you, Nick


回答1:


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

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.

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



来源:https://stackoverflow.com/questions/24315968/apache-avro-c-installation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!