Skip to content

Instantly share code, notes, and snippets.

@leoncamel leoncamel/Makefile
Last active May 18, 2016

Embed
What would you like to do?
minimum libhdfs example
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hdfs.h"
int main(int argc, char **argv) {
// hdfsFS fs = hdfsConnect("default", 0);
hdfsFS fs = hdfsConnect("192.168.1.81", 8020);
const char* writePath = "/tmp/testfile.txt";
hdfsFile writeFile = hdfsOpenFile(fs, writePath, O_WRONLY|O_CREAT, 0, 0, 0);
if(!writeFile) {
fprintf(stderr, "Failed to open %s for writing!\n", writePath);
exit(-1);
}
char* buffer = "Hello, World!";
tSize num_written_bytes = hdfsWrite(fs, writeFile, (void*)buffer, strlen(buffer)+1);
if (hdfsFlush(fs, writeFile)) {
fprintf(stderr, "Failed to 'flush' %s\n", writePath);
exit(-1);
}
hdfsCloseFile(fs, writeFile);
return 0;
}
CC=gcc
JVM_ROOT=/usr/lib/jvm/java-7-openjdk-amd64/
HADOOP_ROOT=/home/xiaolin/work/apache/hadoop-2.7.1
export CLASSPATH=$(shell ${HADOOP_ROOT}/bin/hadoop classpath --glob)
export LD_LIBRARY_PATH=${HADOOP_ROOT}/lib/native:${JVM_ROOT}/jre/lib/amd64/server/
CFLAGS = -O2 -g -Wall -fmessage-length=0 -I${HADOOP_ROOT}/include
OBJS = hello.o
LIBS = -L${HADOOP_ROOT}/lib/native -lhdfs -Wl,-rpath, -Wl,${JVM_ROOT}/jre/lib/amd64/server/libjvm.so
TARGET = hello
all: $(TARGET)
$(OBJS): %.o:%.c
$(CC) $(CFLAGS) -c $< -o $@
$(TARGET): $(OBJS)
$(CC) -o $(TARGET) $(OBJS) $(LIBS)
run:$(TARGET)
./hello
clean:
rm -f $(OBJS) $(TARGET)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.