Solve the problem of directly decompressing C++ static library under Mac

  • 2020-05-10 18:33:05
  • OfStack

Found the problem

The static library of C++ (*.a files) is a compressed package in which all *.o files are packed.

So what I want to try to do is very simple: unzip all the *.o files from the static library, and then use the *.o file links to merge them into a dynamic library. I just double-click on the unzip, and I get 1 heap of *.o. Then I executed the command to generate the dynamic library, which looks like this:


c++ -g -dynamiclib -Wl,-headerpad_max_install_names -o libtest.dylib /usr/lib/libexpat.dylib /usr/lib/libz.dylib -framework ApplicationServices -framework OpenGL *.o 

Result 1 direct error reporting:


ld: file not found: raw_codec.SkRawAdapterCodec.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The solution

Error reporting that this could not be found raw_codec.SkRawAdapterCodec.o File, but I'm sure the file exists. Add the -v parameter as prompted, print the detailed list, and find this raw_codec.SkRawAdapterCodec.o Is the first file to load, indicating that all files may not be recognized from the command line.

I then tested the other commands, on this one alone raw_codec.SkRawAdapterCodec.o Link, no matter what parameters are prompted ld: file not found The error. It appears that the file simply cannot be loaded. Then I tried to find the *.o file in the original project directory before it was packaged as a static library. There is a problem with *.o files extracted from the static library. Therefore, the binary system compares the two files and finds that MD5 is completely 1, which means the content of the file is no problem. So it's a question of permissions? Put two files in the same directory ls -l Command view 1, output the following information:


-rw-r--r-- 1 dom staff  734032 5 25 11:35 raw_codec.SkRawAdapterCodec2.o
-rw-r--r--@ 1 dom staff 734032 5 25 10:25 raw_codec.SkRawAdapterCodec.o

The following file is the wrong file. There is an @ in the permission, and Google is 1. It is said that this is the extended property identification on mac platform, indicating that there are other files besides the standard permission. You can use ls -@l Command to see exactly what the extended properties are. The output is as follows:


-rw-r--r-- 1 dom staff  734032 5 25 11:35 raw_codec.SkRawAdapterCodec2.o
-rw-r--r--@ 1 dom staff 734032 5 25 10:25 raw_codec.SkRawAdapterCodec.o
 com.apple.quarantine  29 

this com.apple.quarantine What the hell is that? Continuing the search, it turned out to be the prompt we often see: "" xxx" is an application downloaded from the Internet. Are you sure you want to open it?" . As a security restriction, this property was introduced in Mac OSX 10.5. If you download it from the browser, or use the unzip command of the system, such as tar, zip, etc., you will automatically add this property to the file. As a result, the first opening requires popover permission. So we can't load 1 straight into this raw_codec.SkRawAdapterCodec.o Because it contains com.apple.quarantine Extend properties.

To delete this property, use the command:


xattr -d com.apple.quarantine  The file name  

Or simply delete this property for all files in the entire folder:


xattr -dr com.apple.quarantine  Folder name  

Test 1, delete com.apple.quarantine The property is good. In fact, a more standardized way to extract static library is to use raw_codec.SkRawAdapterCodec.o0 The ar command will not be automatically added com.apple.quarantine Properties. You can unzip all *.a files in one folder in batches. You can execute this command in the specified directory:


ls *.a | xargs -n1 ar -x

Finally, I tested the previous command and successfully generated the dynamic library

conclusion

The above is about all the content of this article, I hope the content of this article to your study or work can bring 1 definite help, if you have questions you can leave a message to communicate.


Related articles: