linux查看靜態庫
① linux環境下,靜態庫的依賴關系怎麼查
創建靜態庫: ar -rcs test.a *.o 查看靜態庫: ar -tv test.a 解壓靜態庫: ar -x test.a 查看程序依賴態庫: readelf -a xxx|grep library :看面交叉程序hello執行依賴於兩態庫 rebi@ubuntu:~/test$ arm-none-linux-gnueabi-readelf -a hello|grep "library" 0x0000000依 (NEEDED) Shared library: [libgcc_s.so.依] 0x0000000依 (NEEDED) Shared library: [libc.so.陸] rebi@ubuntu:~/test$ 或者:readelf -l hello 即 nm xxx 查看符號 其T表示代碼段U表示其定義所需要確保必須某.o或庫定
② linux查詢靜態庫是arm平台還是x86平台
X86
File: libcrypto.a(e_padlock.o)
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: REL (Relocatable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 248 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 64 (bytes)
Number of section headers: 11
Section header string table index: 8
e_padlock.o: file format elf64-x86-64
ARM
File: libcrypto.a(gost_sign.o)
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: REL (Relocatable file)
Machine: ARM
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 3508 (bytes into file)
Flags: 0x5000000, Version5 EABI
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 12
Section header string table index: 9
gost_sign.o: file format elf32-little
③ linux 怎麼指定靜態鏈接靜態庫
創建靜態庫: ar -rcs test.a *.o 查看靜態庫: ar -tv test.a 解壓靜態庫: ar -x test.a 查看程序依賴的動態庫: readelf -a xxx|grep library 如:可以看到,下面的交叉程序hello執行依賴於如下兩個動態庫。 rebi@ubuntu:~/test$ arm-none-li...
④ linux如何查看靜態庫是不是arm提醒
查看系統內核版本,使用 uname 命令。 以致遠電子的M3352核心板為例,輸入以下命令即可: [root@M3352 ~]# uname -a Linux M3352 3.2.0 #134 Thu Aug 8 15:47:17 CST 2013 armv7l GNU/Linux
⑤ Linux下的靜態庫和動態庫
linux下的靜態庫和動態庫1.製作自己的動態庫和靜態庫linux下動態庫以.so結尾,靜態庫以.a結尾,它們都以lib開頭,比如一個庫名為net,那麼它的全名應該是libnet.so或者libnet.a。我們有兩個文件,hello.c和test.c,下面是兩個文件的內容//hello.c
www.shiwu.com
#include
<stdio.h>void
my_lib_func(){printf(Library
routine
called/r/n);}//test.c#include
<stdio.h>
www.shiwu.com
int
main(){my_lib_func();return
1;}test.c調用了hello.c的方法,我們把hello.c封裝成庫文件。無論是靜態庫還是動態庫,都是由.o文件組成,我們先把gcc
-c
hello.c生成.o文件製作靜態庫ar
crv
libmyhello.a
hello.o,ar是生成靜態庫的命令,libmyhello.a是我的靜態庫名。下一步就是在我的程序中使用靜態庫
可以看到已經有了Library
routine
called的結果,說明調用成功了。下面我們刪除libmyhello.a,看看程序是否還是運行正常
我們發現程序依然運行正常,說明靜態庫已經連接進入我們的程序中製作動態庫
www.shiwu.com
我們看見動態庫libmyhello.so已經生成,下面繼續使用
找不到庫文件,這個時候我們把so文件拷貝到/usr/lib下面
運行成功2.動態庫和靜態庫同時存在的調用規則我們可以發現,不論是動態庫還是靜態庫,程序編譯連接的時候都是加的參數-l,那麼當他們同時存在的時候,程序會選擇動態庫還是靜態庫呢。我們做個嘗試。
我們同時存在libmyhello.a和libmyhello.so,我們發現運行的時候,出現找不到動態庫的錯誤,由此,我們可以得出結論,同時存在動態庫和靜態庫的時候,gcc會優先選擇動態庫作者
梨樹陽光
⑥ 如何查看靜態庫內容 Unix/Linux
以下從最好情況->最壞情況:
1. 最好知道靜態庫的原文件(.c),要是知道聲明文件(.h)也比較好。
2. ar -t YourFile 看其結構,找其中的原文件。
3. 可以將庫文件下到本地用UE打開,然後你就找吧。
另外,看動態庫用 nm -D lib*.so
⑦ 在linux環境下靜態庫(.a)的編譯和使用
假設我們自己編譯一個加法程序,和打亂信印程序。
那麼我們可以通過下面兩個命令將這兩個函數編譯成扒族靜態庫。
那麼我們可以通過下面的命令(任選一種)將main.cpp與靜態庫進行嘩此輪編譯。
待後續補充
⑧ linux下的靜態庫創建與查看,及如何查看某個可執行依賴於哪些動態庫
創建靜態庫:
ar -rcs test.a *.o
查看靜態庫:
ar -tv test.a
解壓靜態庫:
ar -x test.a
查看程序依賴的動態庫:
readelf -a xxx|grep library
如:可以看到,下面的交叉程序hello執行依賴於如下兩個動態庫。
rebi@ubuntu:~/test$ arm-none-linux-gnueabi-readelf -a hello|grep "library"
0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x00000001 (NEEDED) Shared library: [libc.so.6]
rebi@ubuntu:~/test$
或者:readelf -l hello 即可。
nm xxx 查看符號
其中,T表示代碼段,U表示在其它地方定義,所以需要確保必須在某個.o或庫里被定義過。