0

In C++, when you archive object files into a .a file, does it matter the platform?

For example I'm on an x64 platform compiling with x64 compiler, I compile a bunch of CPP files into .o files. Using AR.exe, I archive them into a .a file and distribute that.

Will the .a file be x32, x64 or interchangeable? OR does it depend on the program using the .a file?

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Brandon
  • 22,723
  • 11
  • 93
  • 186
  • A .a file simply contains the objects inside, so it will be whatever platform the source was compiled for. Using tools like lipo, you can distribute cross-platform .a files, however. – Richard J. Ross III Mar 15 '13 at 22:10
  • 1
    The .o files will already be as platform-dependent as it gets, `ar` won't magically fix that. –  Mar 15 '13 at 22:12

1 Answers1

4

Presuming that "compiling with x64 compiler" means that it generates 64-bit code, whether or not it is a 64-bit executable itself, then your .a files will be 64-bit code. They are generated from your .o files, which are 64-bit binaries generated by your compiler. The .a couldn't be anything more or different than the .o files are which constitute it.

John
  • 7,301
  • 2
  • 16
  • 23
  • Ooohhh I see. I was thinking that the .a files will be both some how and whatever program links to it will decide whether it is x32 or x64.. Thanks for clearing that up. – Brandon Mar 15 '13 at 22:14