解压静态库.a文件

首先先准备一个静态库.a文件,比如叫staticLibrary.a,放在桌面的test目录里。

分离arch

首先先file一下staticLibrary.a,看一下该文件包含几种arch。

<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">~  cd Desktop/test
test  ls
staticLibrary.<span class="hljs-operator" style="box-sizing: border-box;">a</span>
test  <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">file</span> staticLibrary.<span class="hljs-operator" style="box-sizing: border-box;">a</span> 
staticLibrary.<span class="hljs-operator" style="box-sizing: border-box;">a</span>: Mach-O universal binary <span class="hljs-operator" style="box-sizing: border-box;">with</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> architectures
staticLibrary.<span class="hljs-operator" style="box-sizing: border-box;">a</span> (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> architecture armv7):   current ar archive <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">random</span> library
staticLibrary.<span class="hljs-operator" style="box-sizing: border-box;">a</span> (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> architecture arm64):   current ar archive <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">random</span> library</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul>

可以看到该文件包含两种arch,分别是armv7和arm64。 
由于下面抽离object的时候必须是要单一的库,所以这里我们之抽出armv7并命名为v7.a:

<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">lipo staticLibrary.<span class="hljs-operator" style="box-sizing: border-box;">a</span> -thin armv7 -output v7.<span class="hljs-operator" style="box-sizing: border-box;">a</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

这时候应该在test目录下多了一个v7.a文件。

抽离.a文件的object

<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">ar -x v7.<span class="hljs-operator" style="box-sizing: border-box;">a</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

你会发现会多出一些.o文件

获取文件

比如刚才多出来了一个View.o文件,使用以下命令进行获取:

<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">nm View<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.o</span> > view<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.m</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

OK 去看一下view.m文件吧

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Windows系统中,通常使用".lib"扩展名而不是".a"扩展名来表示静态库文件。\[2\]然而,如果你有一个以".a"为扩展名的静态库文件,你可以使用MinGW工具来转换它。首先,你需要安装MinGW工具,并确保安装了mingw32-gcc-g++、mingw32-binutils、msys-base和msys-zip这四个组件。然后,打开命令行窗口,进入存放静态库文件的目录。使用命令"ar -x hal.a"来解压静态库中的所有对象文件(.o文件)。接下来,你可以创建一个.def文件来定义导出函数。你可以使用命令"nm -g hal.a"来查看库文件中的导出函数列表,并将函数名填入.def文件中。最后,使用命令"dlltool -d hal.def -l hal.lib"来生成一个新的.lib文件,其中hal.def是导出函数定义文件名,hal.lib是要生成的输出文件名。\[1\]这样,你就可以在Windows系统中使用这个新的.lib文件作为静态库文件了。 #### 引用[.reference_title] - *1* [windows下静态库.a转.lib](https://blog.csdn.net/qq_45662588/article/details/130903311)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [以.a(a为后缀)的文件类型是啥鸭?](https://blog.csdn.net/u010087338/article/details/122520107)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值