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
11
votes
1 answer

Override weak symbols in static library

I want to make a static .a library for my project from multiple sources, some of them define weak functions and others implements them. Let's say as example I have : lib1.c : void defaultHandler() { for(;;); } void myHandler()…
Quentin
  • 1,085
  • 1
  • 11
  • 29
10
votes
1 answer

How are external symbols resolved?

I have two files 37064544_p1.cpp & 37064544_p2.cpp with the same content as shown below : int add(int x,int y) { return x+y; } I compiled them using g++ -c 37064544_p2.cpp -o 37064544_p2.o g++ -c 37064544_p2.cpp -o 37064544_p2.o and added them to…
sjsam
  • 21,411
  • 5
  • 55
  • 102
9
votes
4 answers

How can I extract static libs containing repeated object files?

I'm trying to build a big static library merging two static libraries. In moment I'm using the 'ar' command, extracting objects, for example, from 'a.a' and 'b.a' and then reassembling these objects using 'ar' again: $ ar x a.a $ ar x b.a $ ar r…
Gustavo Meira
  • 2,875
  • 3
  • 21
  • 33
9
votes
1 answer

linking a self-registering, abstract factory

I've been working with and testing a self-registering, abstract factory based upon the one described here: https://stackoverflow.com/a/582456 In all my test cases, it works like a charm, and provides the features and reuse I wanted. Linking in this…
Ethan Coon
  • 751
  • 5
  • 16
8
votes
3 answers

Where can I find the GNU ar file format specification?

I need to access an ar created file, but I cannot find a specification document defining the format. Can someone point me in the right direction?
D. A.
  • 3,369
  • 3
  • 31
  • 34
7
votes
1 answer

order of object files in static library

I know that when linking to multiple static libraries or object files, the order matters (dependent libraries should be listed before their dependencies). I want to know if, when creating a library file with ar, this same rule applies and the order…
Baruch
  • 20,590
  • 28
  • 126
  • 201
7
votes
2 answers

Static library link issue with Mac OS X: symbol(s) not found for architecture x86_64

I'm trying to generate a static library and link it with an execution binary. This is a library function: #include int hello() { return 10; } With these commands, I could get a static library. gcc -c io.c ar -crv libio.a…
prosseek
  • 182,215
  • 215
  • 566
  • 871
7
votes
2 answers

Do I need "ranlib" / "ar -s" for static linking?

I did not find any proper information if and why I need ranlib / ar -s for static linking. Assume I have an application that consists of multiple modules. Each module has its code files in its own folder, and the object files are created in their…
Kijewski
  • 25,517
  • 12
  • 101
  • 143
7
votes
1 answer

ar cannot create archive: "File format not recognized"

I have this makefile libjackpot.a: jackport.o jackpot.o ar -rcs jackport.o jackpot.o jackpot.o: jackpot.cpp jackpot.h g++ jackpot.cpp -std=c++11 -O2 -c jackport.o: jackport.cpp jackpot.h jackport.h g++ jackport.cpp -std=c++11 -O2…
user877329
  • 6,717
  • 8
  • 46
  • 88
7
votes
2 answers

Read/Write files in C

I'm writing a program in C that basically creates an archive file for a given list of file names. This is pretty similar to the ar command in linux. This is how the archive file would look like: ! file1.txt/ 1350248044 45503 13036 100660…
Arian Motamedi
  • 7,123
  • 10
  • 42
  • 82
6
votes
1 answer

Multiple definition within static library

I have a question that is very closely related to Linker does not emit multiple definition error when same symbol coexists in object file and static library, but concerns a slightly different situation. Just like there, I have two .cpp files (say:…
DerAuenlaender
  • 139
  • 2
  • 6
6
votes
1 answer

Autoconf uses wrong AR on OS X

I'm testing on OS X. We have a configure.ac and Makefile.am. Autotools is selecting the wrong AR and ARFLAGS for the platform. It happens with (and without) AM_PROG_AR in Makefile.am: $ egrep 'AR =|ARFLAGS =' Makefile AMTAR = $${TAR-tar} AR =…
jww
  • 97,681
  • 90
  • 411
  • 885
5
votes
1 answer

Archive has no index; run ranlib to add one (when linking with a .a containing a MachO64 object file on Linux)

I tried to create a library and test it, but an error occurred. error code: ./libasm.a: error adding symbols: Archive has no index; run ranlib to add one collect2: error: ld returned 1 exit status I compiled it like this. nasm -f macho64…
AMATEUR_TOSS
  • 256
  • 5
  • 13
5
votes
2 answers

CMake append objects from different CMakeLists.txt into one library

I would like to create a single library from objects from multiple sub-directories, each one containing their own CMakeLists.txt with OBJECT library trick to have multiple targets with different compile options. Here are the files: project_dir |---…
Rakib
  • 791
  • 8
  • 19
5
votes
1 answer

File IO does not appear to be reading correctly

Disclaimer: this is for an assignment. I am not asking for explicit code. Rather, I only ask for enough help that I may understand my problem and correct it myself. I am attempting to recreate the Unix ar utility as per a homework assignment. The…
idigyourpast
  • 714
  • 4
  • 12
  • 24
1
2
3
12 13