سؤال

I've made a C program that uses libsndfile to extract some data from audio files.

What possibilities are there to make the program as portable as possible, preferably without requiring root access when installing?

Libsndfile is not available at the target machines, so i need to somehow package it with my program. Is there a way to statically link the library? I've also looked at some Autotools tutorials, but I'm not sure how to proceed.

I can compile without a hitch on my dev machine, where I installed the libraries using the package manager: apt-get install libsnfile1-dev

The makefile is very simple:

CFLAGS=-std=c99 -Wall -pedantic -g
CLIBS= -lsndfile -lm
BIN=audiodecode
CC=gcc

MAIN=main.o

FILES=

OBJS=$(FILES) $(MAIN)

.PHONY: all
all: clean $(OBJS)
    $(CC) $(CFLAGS) -o $(BIN) $(OBJS) $(CLIBS)

.PHONY: clean
clean:
    rm -f *.o $(BIN)
هل كانت مفيدة؟

المحلول

A lot of packages bundle their dependencies. Examples: rsync (contains a bundled libpopt), gnupg (contains a bundled libz). Other dependencies commonly bundled are gettext or glib. For inspiration look at how these popular open source projects do it.

Put the content of http://www.mega-nerd.com/libsndfile/files/libsndfile-1.0.25.tar.gz into a subdir and add apropriate rules to build the the subdir first.

Untested sample code: OBJS += libsndfile/libsndfile.a

libsndfile/libsndfile.a:
       cd libsdndfile && ./configure --enable-static && $(MAKE)

For Bonus points add a configure script, that check if the system has already installed libsndfile and link to it dynamically.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top