LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-27-2008, 11:54 AM   #1
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 50
using automake for so-library


I am using autotools to build a shared lib. All the docs on the net use either the .a or the .la extension and both require different commands in the Makefile.am file.

What would a really simple Makefile.am look like for a shared library named "foobar" (where the final binary would be named libfoobar.so)?

Thanks.
 
Old 10-27-2008, 07:46 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
The solution is to not specify; use libtool. Look at info libtool, which should also have some info in info automake. libtool will determine the "best type" of library to use based on the system because some systems don't use dynamic linking. Here's an example from one of my projects:
Code:
STANDARD_INCLUDES=-I/usr/include -I/usr/local/include
ALL_INCLUDES=$(STANDARD_INCLUDES) -I$(srcdir)/../.. -I$(srcdir)/../../include/rservr -I$(srcdir)/../../include -I$(srcdir)/../include
AM_CPPFLAGS=-DENABLE_VIRT_ARRAY_ALL $(ALL_INCLUDES)
AM_CXXFLAGS=-ansi -Wall
AM_CFLAGS=-Wall
STANDARD_LIBS=-L/lib -L/usr/lib -L/usr/local/lib
AM_LDFLAGS=--version-info 1:1:0 $(STANDARD_LIBS)
lib_LTLIBRARIES=librservr-filter.la
librservr_filter_la_SOURCES=filter-main.c api-filter.c api-filter.h
librservr_filter_la_LIBADD=
The .la files are just text files used by libtool at link time. You shouldn't ever have to deal with real extensions.
ta0kira

PS You use the .la file when linking within Makefile.am, e.g. if the library above needed to link to libdependency.(so|a) you would add libdependency.la to *_LIBADD, using a path prefix if it's part of the same project and therefore isn't installed yet. libtool will always give you a static library at installation time and a shared library if possible and if not disabled; therefore, normal linking can still be done with -l outside of automake (or within it, but that would be nonstandard.)

This might be a better example:
Code:
STANDARD_INCLUDES=-I/usr/include -I/usr/local/include
ALL_INCLUDES=$(STANDARD_INCLUDES) -I$(srcdir)/../.. -I$(srcdir)/../../include/rservr -I$(srcdir)/../../include -I$(srcdir)/../include
AM_CPPFLAGS=-DENABLE_VIRT_ARRAY_ALL -DRSERVR_RESTRICT_COMMAND_INTERFACE $(ALL_INCLUDES)
AM_CXXFLAGS=-ansi -Wall
AM_CFLAGS=-Wall
STANDARD_LIBS=-L/lib -L/usr/lib -L/usr/local/lib
AM_LDFLAGS=--version-info 1:1:0 $(STANDARD_LIBS)
lib_LTLIBRARIES=librsvp-rqsrvc.la librsvp-rqsrvc-auto.la
librsvp_rqsrvc_la_SOURCES=api-rqsrvc.cpp plugin-rqsrvc.cpp api-rqsrvc.h plugin-rqsrvc.hpp
librsvp_rqsrvc_la_LIBADD=../../libs/command/librservr-command.la
librsvp_rqsrvc_auto_la_SOURCES=rqsrvc-auto.cpp
librsvp_rqsrvc_auto_la_LIBADD=librsvp-rqsrvc.la ../../libs/client/librservr-client.la

Last edited by ta0kira; 10-27-2008 at 08:05 PM.
 
Old 10-28-2008, 06:17 PM   #3
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
I am not sure I fully understand what you are saying.

The libraries are part of a project but my goal is to make them independent from the rest of the project, so that they can be packaged and reused with other projects.

Since I am not very familiar with the autotools just yet I am using the summary from http://markuskimius.wikidot.com/prog...ut:autotools:5 as a guide.

I will just lay out all the details here:

cpp files are inside src/ and header files are inside include/

This is configure.ac
Code:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.61)
AC_INIT([avesta], [1.1], XXX)
AM_INIT_AUTOMAKE([avesta], [1.1])
AC_CONFIG_FILES(Makefile)
AC_CONFIG_HEADER([config.h])

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_LIBTOOL

# set C++ compiling and linkage
AC_LANG_CPLUSPLUS

# Checks for libraries.

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([inttypes.h limits.h malloc.h memory.h stdlib.h string.h unistd.h wchar.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_C_INLINE
AC_TYPE_INT64_T
AC_C_RESTRICT
AC_TYPE_SIZE_T
AC_STRUCT_TM
AC_TYPE_UINT64_T

# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_FUNC_STAT
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([atexit memset mkdir strrchr])

AC_CONFIG_FILES([src/Makefile])
AC_OUTPUT
This is Makefile.am
Code:
SUBDIRS = src
This is src/Makefile.am
Code:
# library to build
lib_LTLIBRARIES = libavesta.la

# the header files
libavesta_la_HEADERS =	../include/avesta_common_base.h \
			../include/avesta_common_config.h \
			../include/avesta_common_debug.h \
			../include/avesta_common.h \
			../include/avesta_common_memory.h \
			../include/avesta_common_neutral.h \
			../include/avesta_common_platform.h \
			../include/avesta_common_types.h \
			../include/avesta_common_utility.h \
			../include/avesta_common_windows.h \
			../include/avesta_endian_from.h \
			../include/avesta_endian.h \
			../include/avesta_endian_sizes.h \
			../include/avesta_endian_swap.h \
			../include/avesta_file.h \
			../include/avesta_file_utility.h \
			../include/avesta.h \
			../include/avesta_hashmap.h \
			../include/avesta_math_consts.h \
			../include/avesta_math.h \
			../include/avesta_math_utility.h \
			../include/avesta_memory_allocator.h \
			../include/avesta_memory.h \
			../include/avesta_memory_reporter.h \
			../include/avesta_memory_tracker.h \
			../include/avesta_memory_utility.h \
			../include/avesta_priorityqueue.h \
			../include/avesta_string.h \
			../include/avesta_string_utility.h \
			../include/_.h
			
# header installation path
libavesta_ladir = $(includedir)/avesta

# the source code
libavesta_la_SOURCES =	$(libavesta_so_headers) \
			avesta_common_debug.cpp \
			avesta_common_memory.cpp \
			avesta_common_utility.cpp \
			avesta_file_utility.cpp \
			avesta_memory_reporter.cpp \
			avesta_memory_tracker.cpp \
			avesta_string_utility.cpp

# libraries needed

# additional include paths needed
INCLUDES = -I$(top_srcdir)/include
This compiles fine but on my Ubuntu system (which I know uses .so-files) all I get is a file called libavesta.la where I would like libavesta.so instead, or even libavesta.so.0.1 or something like that, where installing the libraries would even create the symlinks and everything.

Thanks,
 
Old 10-28-2008, 09:06 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You have to make install for that to happen; it normally won't happen until then with libtool because it will link them in place.
ta0kira
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Dynamically Loaded Libraries & Automake (invalid ELF library error) roby1984 Programming 8 09-12-2008 08:59 AM
LINUX - linking archive (static library) with shared (dynamic) library gurkama Programming 5 03-04-2007 11:11 PM
Scribus installation problem, sez I need automake 1.6 when automake 1.9 is istalled Rockgod2099 Linux - Software 13 11-14-2004 06:37 PM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 04:20 AM
slackware 9 asking for automake 1.6 while i have automake 1.7 gtgoku Slackware 1 10-19-2003 08:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration