[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Using autoconf for a shared library
From: |
Basin Ilya |
Subject: |
Re: Using autoconf for a shared library |
Date: |
Mon, 15 Aug 2016 22:11:04 +0300 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 |
See attached tarball. Unpack,
./autoreconf -fi
./configure
make
make check
make install DESTDIR=`pwd`/../library-dst
>From your makefile:
"so = libpublic.so"
"lib_LTLIBRARIES = libpublic.la"
"ldflags = -shared -Wl,-soname,$(so)"
automatic (soname will be "*.so.0")
"solinkname = -lpublic"
"LDADD = src/libpublic.la"
"install_target = /usr/local"
"install:"
"uninstall:"
automatic
"srcs = $(wildcard src/*.c)"
"libpublic_la_SOURCES = private.c public.c ..."
"objs = $(patsubst %.c,%.o,$(srcs))"
automatic
"includes = include/public.h"
"AM_CPPFLAGS = -I${top_srcdir}/include"
"installed_includes = $(addprefix $(install_target)/,$(includes))"
"include_HEADERS = ../include/public.h"
"cc = gcc"
automatic
"-c , -fPIC"
automatic
"-g -O3 -Wall -Wextra -Wfatal-errors -pedantic-errors"
optionally provide as configure arg: CFLAGS="..."
"privateincludedirs = -Isrc"
not needed, because "src" is current dir during compilation
"publicincludedirs = -Iinclude"
"AM_CPPFLAGS = -I${top_srcdir}/include"
"LD_LIBRARY_PATH="
not needed. Test binaries are built with RPATH
"test:"
"TESTS = test"
"check_PROGRAMS = test"
...
"test" stdout goes to "test.log"
15.08.2016 19:29, Thomas Nyberg пишет:
> Hello,
>
> I've been reading the manuals for autoconf/automake and have been unable
> to get a setup working correctly with autoconf. I've written up a toy
> shared library and right now the Makefile has a rule to install the
> library directly to `/usr/local`. All I really want from autoconf is to
> be able to have `--prefix` user-configurable. I figured it was better to
> use autoconf/automake than reinvent the wheel, but I'm totally unable to
> get it working.
>
> Does anyone here know a source for a very simple example of what is
> needed (configure.ac/Makefile.in) to get this type of setup working?
> I've been reading both manuals, but I can't figure it out. Maybe someone
> here can even immediately see how to do this.
>
> I'm attaching an extremely simplified version of a shared library setup.
> I'm also pasting the text of the files in below in case you just want to
> read directly (instead of extracting something from a random person on
> the internet). Basically if you run `make` it compiles a shared library
> for you with publicly exports one function called `public_func`. If you
> run `make test` it will test it by setting the current directory to
> LD_LIBRARY_PATH. You can install it by running `make install` and then
> ldconfig (though I doubt you want to...). This is the repo structure:
>
> .
> ├── include
> │ └── public.h
> ├── Makefile
> ├── src
> │ ├── private.c
> │ ├── private.h
> │ └── public.c
> └── test.c
>
> Here are the files:
>
> include/public.h
> -----------------------------------
> int public_func(void);
> -----------------------------------
>
> src/public.h
> -----------------------------------
> #include <private.h>
>
>
> int public_func(void) {
> return private_func();
> }
> -----------------------------------
>
> src/private.h
> -----------------------------------
> int private_func(void);
> -----------------------------------
>
> src/private.c
> -----------------------------------
> #include <private.h>
>
>
> int private_func(void) {
> return 1;
> }
> -----------------------------------
>
> test.c
> -----------------------------------
> #include <public.h>
> #include <stdio.h>
>
>
> int main(void) {
> printf("public value: %d\n", public_func());
> return 0;
> }
> -----------------------------------
>
> Makefile
> -----------------------------------
> so = libpublic.so
> solinkname = -lpublic
>
> install_target = /usr/local
>
> srcs = $(wildcard src/*.c)
> objs = $(patsubst %.c,%.o,$(srcs))
>
> includes = include/public.h
> installed_includes = $(addprefix $(install_target)/,$(includes))
>
> cc = gcc
> cflags = -c -g -fPIC -Wall -Wextra -Wfatal-errors -pedantic-errors
> privateincludedirs = -Isrc
> publicincludedirs = -Iinclude
> ldflags = -shared -Wl,-soname,$(so)
>
>
> all: $(so)
>
> $(so): $(objs)
> $(cc) $(ldflags) $(objs) -o $(so)
>
> %.o:%.c
> $(cc) $(cflags) $(privateincludedirs) -c -o $@ $<
>
> clean:
> rm -f *.o src/*.o *.so test
>
> install:
> cp -v $(includes) $(install_target)/include
> cp -v $(so) $(install_target)/lib
> -----------------------------------
>
> Thanks for any help!
>
> Cheers,
> Thomas
>
>
> _______________________________________________
> Autoconf mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/autoconf
>
library.tar.bz2
Description: Binary data