Creating a static library with other libraries



  • 1. Standard Library sort functions on Linked Lists
    Hi all, I was wandering if there was a way to use standard library sort functions such as heapsort on linked lists. I noticed that the qsort had a qsort_r function that would allow you to specifiy the argument being passed to qsort's callback function, I was thinking something like this could be done for heapsort, or modify the call back function to populate the array dynamically. The overall goal here is to use a in-place algorithm that does not require all the data it is working on to be in main memory. I am also trying to avoid re-inveting the wheel a bit. Any advice would be appreciated.

Creating a static library with other libraries

Postby jose_luis_fdez_diaz » Fri, 23 Feb 2007 02:17:36 GMT


Given these static libraries:

  - libstatic1.a
  - libstatic2.a

I link they with a the "main" file: main.c

aCC -lstatic1 -lstatic2 main.c

In libstatic1.a objects files I use classes declared in libstatic2.a.
When I link I get this error:

/usr/ccs/bin/ld: (Warning) The CTTI instantiation with key symbol
"LBXRecord::~LBXRecord()" in file main.o has been overridden by an
explicit definition in file lib/libstatic2.a. This behavior may not be
supported in future releases.

To fix this issue I appended libstatic2.a to libstatic1.a when I
created it:

ar libstatic1.a libstatic1.a *.o

and link with:

aCC -lstatic1 main.c

But I have global vars defined in some libstatic2.a objects files so
the objects files in libstatci1.a don't see them so the linker give "/
usr/ccs/bin/ld: Unsatisfied symbols"

If I extract the libstatic2.a object files:

ar -x libstatic2.a  -->> libstatic2.objs

and attach them to libstatic1.a

ar rv libstatic2.objs *.o

I fix this last issue.

Is there a way to do this without extract the libstatic2.a object

Thanks in advance,
Jose Luis

Re: Creating a static library with other libraries

Postby Paul Pluzhnikov » Fri, 23 Feb 2007 06:19:29 GMT

"jose_luis_fdez_diaz" < XXXX@XXXXX.COM > writes:

This is a bogus command line. Use:

  aCC main.c -lstatic1 -lstatic2

and read this:
if you want to understand why your order of libraries and
sources/objects is wrong.

This is even more bogus: 

- I doubt that is *acutal* command you used;
  you probably did "ar libstatic1.a libstatic2.a *.o"

- besides, the linker will not search libstatic1.a recursively; it
  will simply ignore anything in libstatic1.a which isn't an object
  (and libstatic2.a is not an object; it's an archive).

Yes: use correct link line.

In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.

Similar Threads: to create/merge multiple static library into single static library to create/merge multiple static library into single static library

Vipin < XXXX@XXXXX.COM > writes:

> Is there any other way on UNIX based platforms to generate SINGLE
> STATIC LIBRARY out of other multiple static LIBRARIES and object
> files.

Extract the object files from the existing libraries with `ar x'.  Then
create the new library out of all the extracted object files and any new
ones using `ar rcs'.  (If your version of `ar' does not know the `s'
option, then skip it and run `ranlib' afterwards.)

3.Dynamic Library or Static Library under Linux

Hi, All:

I download a free C++ library form web and it has two forms : static
linked library which ended with .a and dynamic linked library which
ended with .so.

The system seems default to dynamic linked library. How can I use
static linked library?



4.Please help linking shared libraries with third party static library

I'm a Unix newbie and I wouldn't bother you all with this except I've
exhausted the newsgroups and my bookshelf and I can't find the answer.

I'm trying to link a project that uses both static and shared 

Here is the make command

g++ -g -o ../bin/nsre -L../lib -L/lib -shared-libgcc -Xlinker
-levent -lnmutilities -lnsshared -ldb -lnsengine -lbuilder
-lxerces-c1_6_0 -Xlinker -Bstatic -lssce  nsre.o

/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status
make: *** [all] Error 1

where ssce is libssce.a and all the rest are is in /lib which is in the library path as you can see 
there.  I also added /lib to my LD_LIBRARY_PATH environment variable
which didn't change the error.  

Can you offer any hints?
Thank you for any advice

5.Library Versions, Static Binaries, or Force Loaded Libraries

I should start by saying that although I've been doing a fair amount of
programming in Java and Perl, I have essentially no background in C and am
working with what I've pieced together in trying to solve a current
problem.  I need to get a program (plink, part of PuTTY) to run from a CD
on different Linux computers.  Ideally I'd like a static version of the
file that I could count on running on any x86 based computer running Linux
(although it is likely I can count on at least a 2.x kernel -- nothing

I've checked a working executable with ldd and found it's linked against 2


And if I'm using a 2.6 kernel, of course it also lists,
which I hear is normal on a 2.6 kernel (I can't find it, but understand it
is not an actual file).

I notice that on my system /lib/tls/i686/cmov/ is linked
to /lib/tls/i686/cmov/  I've checked a few other distros,
working with LiveCDs, and found that in one it was linked to 
I've also noticed something similar for

I'd like to get a static version of plink, but can't find one anywhere.  I
understand I can compile a static version, but have to have static versions
of the files it links to.  I seriously don't think I know enough to compile
a static version of libc, and can't find one.

1) Is there a place I can download static versions of libraries for Linux so
I could compile this using statically linked libraries?
2) Since both files are linked to different versions of other versions of
themselves, that leads me to ask if I can count on finding
and on most (if not all) Linux systems and expect those files to
be links to the current version of those libraries?
3) I understand if I'm running from a bash shell, I can set the env variable
LD_LIBRARY_PATH and when a program is launched, it will check in the
specified directory (or directories) first for the libraries it needs. 
I've tried this with another program and got nothing but seg faults.  Is
this possible and do I need specially compiled libraries for it to work?

My thoughts are that, if I'm lucky, I can count on and being on pretty much any Linux system and being links to the
current version of the corresponding libraries, so I can count on plink
running okay when I run it from a CD on almost any system.  If that doesn't
work, I'm hoping I can either use LD_LIBRARY_PATH to force loading of the
specific library file or create a static binary.

Since I know so little about C and building C programs, I realize I may be
way off on what I've worked out, or that these ideas are either much harder
than they sound, or that there may be a better way to do this.  Any answers
to my questions or any suggestions, links, or other information is greatly

Thank you!


6. Create static library from application

7. Creating (and linking against) a static library on AIX 5.3 using gcc/g++

8. Creating and linking against static library

Return to unix


Who is online

Users browsing this forum: No registered users and 80 guest