Cross-Compiling libghttp for Embedded ARM File Uploads
Resource-constrained embedded platforms often exclude full-featured HTTP clients like cURL due to binary size limitations. The libghttp library offers a compact alternative for ARM-based devices requiring cloud storage connectivity.
Compiling the Core Library
Fetch the source repostiory:
git clone https://github.com/sknown/libghttp.git
cd libghttp
Adapt the build configuration for cross-compilation by defining toolchain variables:
TARGET_ARCH = arm-linux-gnueabihf
COMPILER = $(TARGET_ARCH)-gcc
ARCHIVER = $(TARGET_ARCH)-ar
DEFINES = -DGHTTP_MAJOR_VERSION=1 \
-DGHTTP_MINOR_VERSION=0 \
-DGHTTP_MICRO_VERSION=9 \
-DPACKAGE=\"libghttp\" \
-DVERSION=\"1.0.9\"
CFLAGS = -O2 -fPIC -Wall $(DEFINES)
OBJECTS = http_core.o http_parse.o http_net.o http_util.o \
http_time.o http_encode.o http_auth.o http_uri.o
STATIC_LIB = libghttp.a
SHARED_LIB = libghttp.so
all: $(STATIC_LIB) $(SHARED_LIB)
$(STATIC_LIB): $(OBJECTS)
$(ARCHIVER) crs $@ $(OBJECTS)
$(SHARED_LIB): $(OBJECTS)
$(COMPILER) -shared -o $@ $(OBJECTS)
%.o: %.c
$(COMPILER) $(CFLAGS) -c $< -o $@
clean:
rm -f $(OBJECTS) $(STATIC_LIB) $(SHARED_LIB)
Build the libraries:
make
Building the Storage Client
For Qiniu cloud integration, obtain the SDK wrapper:
git clone https://github.com/jemygraw/libghttp-qiniu.git
Create a Makefile referecning your libghttp installation:
ARCH = arm-linux-gnueabihf
CC = $(ARCH)-gcc
GHTTP_DIR = ./libghttp
CFLAGS = -std=c99 -I$(GHTTP_DIR)/include -L$(GHTTP_DIR)/lib
LDFLAGS = -lghttp
SOURCES = sdk/qiniu_client.c app/upload_tool.c
OUTPUT = arm-upload
all:
$(CC) $(CFLAGS) $(SOURCES) -o $(OUTPUT) $(LDFLAGS)
Compile the upload utility:
make
The output binary executse HTTP POST requests via libghttp, transmitting files to cloud storage endpoints while maintaining a minimal footprint suitable for embedded deployments.