Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Cross-Compiling libghttp for Embedded ARM File Uploads

Tech 1

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.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.