Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-17-2011, 09:50 AM   #1
LQ Newbie
Registered: Mar 2011
Posts: 14

Rep: Reputation: 0
configure with static libs


I am developing an embedded device using arm platform and there I want to install a mad player in the target. for that I want to copile it in my host with static libraries. I already tried using
--enable-static --disable-shared
options in the configuration command. Although the command generates static libs, the executable program still requires shared libs when I try command "arm-linux-readelf -d /location/madplay "

what should I do in order to build the program completely static ?

thank you.
Old 09-17-2011, 11:03 AM   #2
Senior Member
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
You make a static library with the ar utility; you have a bunch of object files (.o) and you
for file in *.o
     ar cq libname.a ${file}
ranlib libname.a
If you want to see what's getting added add v to cqv. If you've already created the library and are adding or changing functions, use the "replace" directive instead of cq; i.e., use rv.

You can also do this in a Makefile (make "knows" how to execute ar). This is a a small sample of a huge Makefile for building a library of Numerical Recipes functions. It's edited for size and thus isn't actually usable but if you create a Makefile of this form, you'll build static libraries of your object code (and, a bonus, if you edit any of he contained functions and then execute make only the changed object file will be replaced in the library archive).
#       Define this as the parent directory where your include, lib and bin directories live
#       for example, /home/userid (${HOME}), /usr, /usr/local and so on


MAKEFILE =      Makefile

#       use whichever one of these is for your system (don't add any additional flags, not needed)
#CFLAGS =       -xarch=native -xO3 -DANSI -I$(BASDIR)/include   # Solaris 32-bit
#CFLAGS =       -xarch=native64 -xO3 -DANSI -I$(BASDIR)/include # Solaris 64-bit
#CFLAGS =       -O2 -DANSI -I$(BASDIR)/include                  # Linux 32-bit
CFLAGS  =       -O2 -FPIC -m64 -DANSI -I$(BASDIR)/include       # Linux 64-bit

OWNER   =       ${LOGNAME}

GROUP   =       ${GRPNAME}

LIBDIR  =       $(BASDIR)/lib

LMASK   =       0644

LIBRARY =       libnr.a

#       Do not fiddle with anything below here unless you really, REALLY know what you're doing

#       Do not remove target when quit or delete is hit:

OBJECTS =       addint.o airy.o amebsa.o amoeba.o amotry.o amotsa.o anneal.o \
        anorm2.o arcmak.o arcode.o arcsum.o asolve.o atimes.o avevar.o \
        zrhqr.o zriddr.o zroots.o

SOURCES =       addint.c airy.c amebsa.c amoeba.c amotry.c amotsa.c anneal.c \
        anorm2.c arcmak.c arcode.c arcsum.c asolve.c atimes.c avevar.c \
        hundreds missing here
        zrhqr.c zriddr.c zroots.c

ALL:            $(LIBRARY)

# This is what adds object file to your archive file
$(LIBRARY):     $(LIBRARY)(airy.o) $(LIBRARY)(amoeba.o) $(LIBRARY)(amotry.o) \
        $(LIBRARY)(dlinmin.o) $(LIBRARY)(dbrent.o) $(LIBRARY)(df1dim.o) \
        hundreds missing here
        $(LIBRARY)(f1dim.o) $(LIBRARY)(mnbrak.o) $(LIBRARY)(nrutil.o)

# These are the dependencies for every source code file
$(LIBRARY)(addint.o): $(BASDIR)/include/nr.h

$(LIBRARY)(airy.o): $(BASDIR)/include/nr.h

$(LIBRARY)(amebsa.o): $(BASDIR)/include/nr.h \

$(LIBRARY)(amoeba.o): $(BASDIR)/include/nr.h \

$(LIBRARY)(amotry.o): $(BASDIR)/include/nr.h \

$(LIBRARY)(amotsa.o): $(BASDIR)/include/nr.h \

$(LIBRARY)(anneal.o): $(BASDIR)/include/nr.h
hundreds missing here

install:        $(LIBRARY)
        cp $(LIBRARY) $(LIBDIR)
        cd $(LIBDIR);\
        chown $(OWNER) $(LIBRARY);\
        chgrp $(GROUP) $(LIBRARY);\
        chmod $(LMASK) $(LIBRARY)

        cd $(LIBDIR);\
        rm -f $(LIBRARY)

        rm -f $(OBJECTS)

        rm -f $(OBJECTS) $(LIBRARY)
You simply type make, wait awhile, make install which will install libname.a in your chosen lib directory (defined a the top of Makefile).

Hope this helps some.
1 members found this post helpful.
Old 09-17-2011, 01:00 PM   #3
LQ Newbie
Registered: Mar 2011
Posts: 14

Original Poster
Rep: Reputation: 0

thanks for reply.I still don't understand some parts in your post. I will try and let you know the result.

thank you.
Old 09-17-2011, 02:01 PM   #4
Senior Member
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
Well, maybe it wasn't all that clear -- so let me back up a little.

A static library is created by the ar (archive) utility and contains compiled object files (.o files). It will be named libsomething.a so that you can link a program with a -lsomething. The math library, for example, is named libm.a and you link it with -lm. If you look in /usr/lib (or /usr/lib64 there are quite a few static libraries named libsomethng.a; that's what they are, they were created with the ar utility, and you link them to a program with -lsomething.

How you create a static library is laid out in the Makefile example above. As I mentioned, make knows how to create a static library using a compiler and the ar utility if the Makefile is put together as in the example. You have source files (say, .c), you want to have object files (.o) and you want those object files put into a searchable archive file (aka "library") that can be linked with -lsomething.

The Makefile syntax that does this is
$(LIBRARY):     $(LIBRARY)(function_name.o) \
The make utility has built-into it what that syntax means and what to do with it.

The other lines that are important are the dependency lines:
$(LIBRARY)(function_name.o): $(BASDIR)/include/header_file.h
The tokens that are used, LIBRARY, BASDIR, and others are replaced with their definitions (at the top of the Makefile) for human convenience -- much easier to type LIBRARY that to type libsomethig.a over and over again. The file also takes advantage of make built-in token definitions such as CFLAGS (which we have added to for our particular use).

Tokens enclosed in braces ( {} ) are system environment variables, those enclosed in parens ( () ) are locally defined in the Makefile.

It's worth your time and effort to get to know make if you're going to be doing development work for any length of time -- makes your life much, much easier.

Hope this helps some.


arm9, configure, cross-compile, lib, static

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How do I install mhash with static libs? randyvalpobb Linux - Newbie 2 05-31-2008 08:24 AM
Making a static lib from objects + static libs kovacsp Programming 2 12-19-2007 12:53 PM
kwrite on Xfce WinMgr I want to try gccing with static libs garthur Linux - Software 0 01-08-2007 08:06 AM
Configure keeps asking for Qt include/libs when they are there Ephracis Linux - Software 2 02-10-2006 03:12 AM
Qt Libs Static or Shared magicm Slackware 2 10-15-2003 05:05 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:11 PM.

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