Skip to content

Instantly share code, notes, and snippets.

@gniuk
Last active February 23, 2022 03:11
Show Gist options
  • Save gniuk/9d12fa223f58c2675e97b268ee09aee4 to your computer and use it in GitHub Desktop.
Save gniuk/9d12fa223f58c2675e97b268ee09aee4 to your computer and use it in GitHub Desktop.
strip static library with duplicated object file names; strip .a with duplicated .o names
#!/bin/bash
## note: if more than two object files with the same name then you need modify the code.
lib="your_static_lib.a"
origin_lib="origin_${lib}"
mv $lib $origin_lib
dups=$(ar t $origin_lib | sort | uniq -c | sort | grep "^ *2 " | awk '{print $NF}')
mkdir -p output1 output2
cd output1
ar x ../${origin_lib}
for i in ${dups}; do
echo "$i"
ar xN 1 ../${origin_lib} "$i"
done
strip --strip-unneeded *.o
cd ../output2
for i in ${dups}; do
echo "$i"
ar xN 2 ../${origin_lib} "$i"
done
strip --strip-unneeded *.o
cd ..
ar cvqs ${lib} output1/*.o output2/*.o
# rm -rf output1 output2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment