Questions tagged [unix-ar]

The Unix archiver utility, used primarily for maintaining static libraries. For questions about augmented reality, use [augmented-reality], not this tag.

This tag is for questions about the Unix archiver utility, commonly known as "ar". It is used to maintain groups of files as a single file, known as an archive. Today, it is primarily used to create and maintain static libraries in conjunction with a linker.

For more information on ar, see Wikipedia.

NOTE: Do not use this tag for questions about augmented reality! The tag should be used instead.

181 questions
176
votes
6 answers

Linking static libraries to other static libraries

I have a small piece of code that depends on many static libraries (a_1-a_n). I'd like to package up that code in a static library and make it available to other people. My static library, lets call it X, compiles fine. I've created a simple sample…
Jason Sundram
  • 12,225
  • 19
  • 71
  • 86
126
votes
9 answers

How to merge two "ar" static libraries into one?

I have 2 static Linux libraries, created by ar cr, libabc.a and libxyz.a. I want to merge them into one static library libaz.a. How can I do this. I want to create a merged static library, not to give both libraries to final link of applications.
osgx
  • 90,338
  • 53
  • 357
  • 513
41
votes
1 answer

what is the difference between ranlib, ar, and ld for making libraries

To make libraries in c++/unix from *.o files, I have noticed two different ways in my project (legacy code): ar qc libgraphics.a *.o ranlib libgraphics.a and ld -r -o libgraphics.a *.o What is the difference between the two approaches, and which…
R71
  • 4,283
  • 7
  • 32
  • 60
31
votes
3 answers

What does the "rcs" option in ar do?

I did read the man file but it does not help. rcs seems to be the most popular option to pass to ar, but the meaning isn't so clear to me. So c means to create a new archive, but then why use r? which seems to stand for "replace"? What will the s…
user3810155
25
votes
5 answers

Possible to use a .dll on Linux

Question: Is it possible to compile a program on linux using a .dll file? Where this is going: This .dll will be used to write a php extension to some proprietary software from a third party. Background and Research: I have been given a library…
random_hero
  • 253
  • 1
  • 3
  • 4
19
votes
5 answers

Static library built for archive which is not the architecture being linked (x86_64)

I am experiencing what seems to be the same problem when I try to compile two different programs. Each of them creates first a static library and then the main application linking that library. I am working on Mac OS Mavericks with gcc 4.7.2.…
ChronoTrigger
  • 8,459
  • 1
  • 36
  • 57
17
votes
1 answer

How to observe the content of static lib in mac OS?

I create a static library project in my xCode and build a .a named mylib.a. There some code (.m files) and another static lib file named common.a to inform the static library nylib.a. But I doubt that if the contend of common.a are pack in the…
qiushuitian
  • 1,261
  • 4
  • 19
  • 31
16
votes
2 answers

how to ar x filename.a to different directory

Is there any ar option to extract objects to a different directory ? Any way to extract them to tmp below ? [test]# ls -l total 1828 -rw-r--r-- 1 root root 1859628 Aug 24 02:10 libclsr11.a drwxr-xr-x 2 root root 4096 Aug 24 02:12 tmp [test]# ar x…
Jon
  • 215
  • 3
  • 9
15
votes
4 answers

Static library having object files with same name (ar)

A bit context. Let's say I have source files, which need to end up in a static library. Let's say there are two cpp files a.cpp and a.cpp located in two different subdirectories. Something like this: foo/a.h foo/a.cpp bar/a.h bar/a.cpp Their…
murrekatt
  • 5,961
  • 5
  • 39
  • 63
14
votes
3 answers

Combining static libraries

Suppose I have three C static libraries say libColor.a which depends on *libRGB.*a which in turn depends on libPixel.a . The library libColor.a is said to depend on library libRGB.a since there are some references in libColor.a to some of symbols…
AIB
  • 5,894
  • 8
  • 30
  • 36
13
votes
1 answer

Turn thin archive into normal one

I'm building V8, and by default it builds as a "thin" archive, where the .a files essentially just contain pointers to the object files on your filesystem instead of containing the object files themselves. See man ar for details. I want to be able…
Matt Kline
  • 10,149
  • 7
  • 50
  • 87
12
votes
2 answers

Is using --start-group and --end-group when linking faster than creating a static library?

If one builds static libraries in one's build scripts and one wants to use those static libraries in linking the final executable, the order one mentions the .a files is important: g++ main.o hw.a gui.a -o executable If gui.a uses something defined…
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
12
votes
5 answers

`ar` library override timestamp

the .a archive format header requires a timestamp. This has led to countless headaches when I rebuild a static library, mainly because I can't exactly reproduce the original binary. For example (this is on my Mac, but the same thing happens in x64…
Foo Bah
  • 25,660
  • 5
  • 55
  • 79
12
votes
2 answers

OS X linker unable to find symbols from a C file which only contains variables

I am having problems with the linker when porting a C library from Linux (Ubuntu) to OS X. The C code is auto-generated from Matlab, so ideally I don't want to change the code itself. The problem seems to be in a C file which contains ONLY…
geekydel
  • 183
  • 1
  • 6
11
votes
1 answer

building static library that depends on another static library

I have a case where there are two libraries lib1 and lib2. lib2 has dependencies on lib1. In my case lib2 is basically a high level wrapper around the functions inside lib1. The final application is just going to use functions from lib2 by including…
Trinayan Baruah
  • 323
  • 2
  • 10
1
2 3
12 13