Extract a FAT .a file Mac - iphone

I have a FAT .a archive on my Mac (a library) and I just wanted to know how I could extract the files from it?

lipo input_file -extract architecture -output output_file
This is for extracting a single architecture of a Universal Binary archive. Not sure if this helps, though.

Related

Can't force gcc linker remove unuse function

I use gcc (via eclipse) to compile c code with .a file staticly , But I saw that the final binary file contains function from .a file that I don't call them from my C code.
I don't have the source code of .a file , only the .a file itself.
Tried to remove them by add -Wl,-gc-sections and -ffunction-sections to gcc , but still I saw many function in final binary file from .a file that didn't called from my c code.
Why is that?

STM32 Eclipse + ARM GNU toolchain error linker

I use Eclipse + ARM plugin to build my projects. When I needed to use in my project the StemWin library, I configured my IDE to use external library.
I set
Preferences -> C/C++ General -> Paths and Symbols
I added in "Library Paths" the link to my folder includes library.
I also added the name of my library in tab "Library".
I checked the settings in the compiler tab and I ascertained all should be good.
When I tried to build my project I got an error from linker:
cannot find -lMyLib.a Hello C/C++ Problem
I double checked the name of my library and link, all are correct. This is the output of my linker:
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -L"C:\lib"
-T"C:\arm_toolchain\stm32_workspace\Hello\LinkerScript.ld" -Wl,
-Map=output.map -Wl,--gc-sections -o "Hello.elf" #"objects.list" -lMyLib.a
What should I do from here?
I faced the same problem before.
-l:STemWin526_CM4_GCC.a
-L"C:\Edu_Workspace\STM32F4\stm32f4_bsp_template\Drivers\Middlewares\ST\STemWin\Lib"
Above are my working settings.
With -l:<archive file name> the colon : is important for archive file linking.
And -L will contain library path.
Also for stemwin make sure to compile with hardware floating point
-mfloat-abi=hard -mfpu=fpv4-sp-d16
the convention for the -l option of the linker (say you give -lMyLib.a as a linker option) is to search for a library file with "lib" prepended to the given name and .a (or .so) appended, i.e. your command line searches for a file libMyLib.a.{a,so} which is probably not how it's named.
Either you rename your library according to this convention or give it to the linker command line omitting -l (provided your IDE allows you to do so).
Looks like the problem is in -lMyLib.a which means you're trying to link a static library as a dynamic one.
To link a static lib you have to use its path as with ordinary .o files: ... /path/to/MyLib.a
and the resulting command line should look something like
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -L"C:\lib" -T"C:\arm_toolchain\stm32_workspace\Hello\LinkerScript.ld" -Wl,-Map=output.map -Wl,--gc-sections -o "Hello.elf" #"objects.list" /path/to/MyLib.a
UPDATE:
Although it might fix the issue, turns out it's not true:
-llibrary
-l library
...
Normally the files found this way are library files—archive files whose members are object files. The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file, it is linked in the usual fashion. The only difference between using an -l option and specifying a file name is that -l surrounds library with ‘lib’ and ‘.a’ and searches several directories.
(https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html)

Compile iOS strings files from command line

Compiled iOS apps have localized strings files compiled into binary PList files and they are converted by Xcode.
Is there any way to compile them from command line from the original strings files?
I think I found what I was looking for:
plutil -convert binary1 Localizable.strings
plutil it is.
The build task is here /Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/CopyStringsFile.xcspec
It runs copystrings ruby script, which is based on iconv and plutil

Printing objects inside a lib file

What is the command to print .o files inside a .a file inside ?
man ar tells you the syntax is ar t name/of/lib as in ar t /usr/lib/libc.a

Extract object (*.o) files from an iPhone static library

I have a set of iPhone static libraries (a *.a file) in which I only call a few of the classes from.
I have used AR in the past (with linux libraries) to extract the object files from the static library, remove the unwanted object files and rearchive.
However, when I try this with an iPhone compliled static library, I get the following error:
ar: CustomiPhoneLib.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
ar: CustomiPhoneLib.a: Inappropriate file type or format
Does anyone know how to extract the object files from an iphone compiled static library? Doing thie could potentially reduce the final file size.
That’s because your CustomiPhoneLib.a is a fat library, i.e., a library that contains more than one target architecture, namely armv6 and armv7 on iOS. You can use lipo to extract a specific architecture into another .a file, use ar and ranlib to manipulate it at will, and then use lipo again to recombine the manipulated .a files into a single .a fat file. For instance,
lipo CustomiPhoneLib.a -thin armv6 -output CustomiPhoneLibarmv6.a
lipo CustomiPhoneLib.a -thin armv7 -output CustomiPhoneLibarmv7.a
### use ar and ranlib at will on both files
mv CustomiPhoneLib.a CustomiPhoneLib.a.original
lipo CustomiPhoneLibarmv6.a CustomiPhoneLibarmv7.a -create -output CustomiPhoneLib.a
However, you don’t have to do this for the reason you’ve mentioned. The linker will only pull object (.o) files from a library (.a) if it needs to resolve some symbol reference. Therefore, if a library contains an object file whose symbols are never referenced during the linking process (i.e., symbols that are not effectively used), that object file won’t make it into the executable.
Code:
ar -t mylib.a
This will list all of the files in the archive.
Code:
ar -xv mylib.a myobj.o
This will extract the object give myobj.o from the library mylib.a.