① Android下怎么使用LDD查看依赖库
Android下没有ldd可以使用,在进行ndk开发的时候,检查库的依赖项特别麻烦。有两个解决方案:
1、将linux的的ldd移植过去。因为android也是基于linux的,所以将ldd移植过去是完全可能的,google一下吧,这不是本文的重点;
2、现成的。ndk已经提供了工具,在ubuntu下执行locate readelf,你会发现有这些输出:
/mydroid/external/elfutils/src/readelf.c
/mydroid/prebuilt/darwin-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-readelf
/mydroid/prebuilt/darwin-x86/toolchain/arm-eabi-4.2.1/man/man1/arm-eabi-readelf.1
/mydroid/prebuilt/darwin-x86/toolchain/arm-eabi-4.3.1/bin/arm-eabi-readelf
/mydroid/prebuilt/darwin-x86/toolchain/arm-eabi-4.3.1/man/man1/arm-eabi-readelf.1
/mydroid/prebuilt/darwin-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-readelf
/mydroid/prebuilt/darwin-x86/toolchain/arm-eabi-4.4.0/man/man1/arm-eabi-readelf.1
/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-readelf
/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/man/man1/arm-eabi-readelf.1
/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.3.1/bin/arm-eabi-readelf
/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.3.1/man/man1/arm-eabi-readelf.1
/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-readelf
/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/man/man1/arm-eabi-readelf.1
/mydroid/prebuilt/linux-x86/toolchain/i686-unknown-linux-gnu-4.2.1/bin/i686-unknown-linux-gnu-readelf
/mydroid/prebuilt/linux-x86/toolchain/i686-unknown-linux-gnu-4.2.1/man/man1/i686-unknown-linux-gnu-readelf.1
/mydroid/prebuilt/linux-x86/toolchain/sh-4.3.3/bin/sh-linux-gnu-readelf
/usr/android/android-ndk-r4b/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin/arm-eabi-readelf
/usr/android/android-ndk-r4b/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/arm-eabi-readelf
/usr/bin/readelf
/usr/share/man/man1/readelf.1.gz
加粗的部分就是你可以使用的工具了。
测试一下:
当你完成android的编译后,测试如下:
root@dylan-ubuntu:/mydroid/out/target/proct/generic/system/bin# /usr/android/android-ndk-r4b/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin/arm-eabi-readelf -d test_pvauthorengine
Dynamic section at offset 0x20b00 contains 26 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libopencore_author.so]
0x00000001 (NEEDED) Shared library: [libopencore_common.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000001 (NEEDED) Shared library: [libstdc++.so]
0x00000001 (NEEDED) Shared library: [libm.so]
0x00000020 (PREINIT_ARRAY) 0x28000
0x00000021 (PREINIT_ARRAYSZ) 0x8
0x00000019 (INIT_ARRAY) 0x28008
0x0000001b (INIT_ARRAYSZ) 8 (bytes)
0x0000001a (FINI_ARRAY) 0x28010
0x0000001c (FINI_ARRAYSZ) 8 (bytes)
0x00000004 (HASH) 0x8108
0x00000005 (STRTAB) 0x8fb0
0x00000006 (SYMTAB) 0x85a0
0x0000000a (STRSZ) 4570 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000015 (DEBUG) 0x0
0x00000003 (PLTGOT) 0x28bf8
0x00000002 (PLTRELSZ) 1144 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0xa19c
0x00000011 (REL) 0xa18c
0x00000012 (RELSZ) 16 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x00000000 (NULL) 0x0
root@dylan-ubuntu:/mydroid/out/target/proct/generic/obj/lib# /usr/android/android-ndk-r4b/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin/arm-eabi-readelf -d libopencore_common.so
Dynamic section at offset 0xcc448 contains 36 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libutils.so]
0x00000001 (NEEDED) Shared library: [libcutils.so]
0x00000001 (NEEDED) Shared library: [libui.so]
0x00000001 (NEEDED) Shared library: [libhardware.so]
0x00000001 (NEEDED) Shared library: [libandroid_runtime.so]
0x00000001 (NEEDED) Shared library: [libdrm1.so]
0x00000001 (NEEDED) Shared library: [libmedia.so]
0x00000001 (NEEDED) Shared library: [libskia.so]
0x00000001 (NEEDED) Shared library: [libvorbisidec.so]
0x00000001 (NEEDED) Shared library: [libsonivox.so]
0x00000001 (NEEDED) Shared library: [liblog.so]
0x00000001 (NEEDED) Shared library: [libicuuc.so]
0x00000001 (NEEDED) Shared library: [libcamera_client.so]
0x00000001 (NEEDED) Shared library: [libsurfaceflinger_client.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000001 (NEEDED) Shared library: [libstdc++.so]
0x00000001 (NEEDED) Shared library: [libm.so]
0x0000000e (SONAME) Library soname: [libopencore_common.so]
0x00000010 (SYMBOLIC) 0x0
0x00000019 (INIT_ARRAY) 0xc7000
0x0000001b (INIT_ARRAYSZ) 16 (bytes)
0x00000004 (HASH) 0xb4
0x00000005 (STRTAB) 0xc6fc
0x00000006 (SYMTAB) 0x420c
0x0000000a (STRSZ) 86133 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000003 (PLTGOT) 0xcc588
0x00000002 (PLTRELSZ) 1032 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x22144
0x00000011 (REL) 0x21774
0x00000012 (RELSZ) 2512 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x6ffffffa (RELCOUNT) 4012
0x00000000 (NULL) 0x0
转载
② linux源码包怎么查看依赖关系
一、可执行文件/二进制文件依赖共享库
ldd命令用来查看可执行文件依赖的共享库文件。
$ ldd --help
Usage: ldd [OPTION]... FILE...
--help print this help and exit
--version print version information and exit
-d, --data-relocs process data relocations
-r, --function-relocs process data and function relocations
-u, --unused print unused direct dependencies
-v, --verbose print all information
示例:
$ ldd helloworld
二、共享库依赖共享库关系
上面的ldd命令无法查看共享库的依赖关系,因为共享库本身并不是可执行文件,我们可以使用
objmp -x libhelloworld.so | grep NEEDED
其中,libhelloworld.so是你的库名称。
附:
readelf命令用于读取ELF Header信息
③ Linux使用ldd命令查看程序调用了哪些动态库
名称 ldd - 打印共享库的依赖关系
大纲 ldd [选项]...文件...
描述 ldd 输出在命令行上指定的每个程序或共享库需要的共享库。
选项
--version
打印ldd的版本号
-v --verbose
打印所有信息,例如包括符号的版本信息
-d --data-relocs
执行符号重部署,并报告缺少的目标对象(只对ELF格式适用)
-r --function-relocs
对目标对象和函数执行重新部署,并报告缺少的目标对象和函数(只对ELF格式适用)
--help 用法信息
或者看看《linux就该这么学》,具体关于这一章地址3w(dot)linuxprobe/chapter-02(dot)html.
④ 查询linux应用程序运行依赖哪些库
在x86下,为了查看程序所依赖的库,可以使用ldd命令
但如果是使用arm-linux-gcc 等交叉编译环境编译出来的程序,则要使用readelf命令来查看了
⑤ 查询Linux应用程序运行依赖哪些库
在x86下,为了查看程序所依赖的库,可以使用ldd命令
但如果是使用arm-linux-gcc 等交叉编译环境编译出来的程序
⑥ Android下怎么使用LDD查看依赖库
Android下没有ldd可以使用,在进行ndk开发的时候,检查库的依赖项特别麻烦。有两个解决方案:
1、将linux的的ldd移植过去。因为android也是基于linux的,所以将ldd移植过去是完全可能的,google一下;
2、现成的。ndk已经提供了工具,在ubuntu下执行locate readelf,会发现有这些输出。
⑦ linux c 段错误如何定位
1. 段错误是什么
一句话来说,段错误是指访问的内存超出了系统给这个程序所设定的内存空间,例如访问了不存在的内存地址、访问了系统保护的内存地址、访问了只读的内存地址等等情况。这里贴一个对于“段错误”的准确定义(参考Answers.com):
A segmentation fault (often shortened to segfault) is a particular error condition that can occur ring the operation of computer software. In short, a segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (e.g., attempts to write to a read-only location, or to overwrite part of the operating system). Systems based on processors like the Motorola 68000 tend to refer to these events as Address or Bus errors.
Segmentation is one approach to memory management and protection in the operating system. It has been superseded by paging for most purposes, but much of the terminology of segmentation is still used, "segmentation fault" being an example. Some operating systems still have segmentation at some logical level although paging is used as the main memory management policy.
On Unix-like operating systems, a process that accesses invalid memory receives the SIGSEGV signal. On Microsoft Windows, a process that accesses invalid memory receives the STATUS_ACCESS_VIOLATION exception.
2. 段错误产生的原因
2.1 访问不存在的内存地址
#include<stdio.h>
#include<stdlib.h>
void main()
{
int *ptr = NULL;
*ptr = 0;
}
2.2 访问系统保护的内存地址
#include<stdio.h>
#include<stdlib.h>
void main()
{
int *ptr = (int *)0;
*ptr = 100;
}
2.3 访问只读的内存地址
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
char *ptr = "test";
strcpy(ptr, "TEST");
}
2.4 栈溢出
#include<stdio.h>
#include<stdlib.h>
void main()
{
main();
}
等等其他原因。
3. 段错误信息的获取
程序发生段错误时,提示信息很少,下面有几种查看段错误的发生信息的途径。
3.1 dmesg
dmesg可以在应用程序crash掉时,显示内核中保存的相关信息。如下所示,通过dmesg命令可以查看发生段错误的程序名称、引起段错误发生的内存地址、指令指针地址、堆栈指针地址、错误代码、错误原因等。以程序2.3为例:
panfeng@ubuntu:~/segfault$ dmesg
[ 2329.479037] segfault3[2700]: segfault at 80484e0 ip 00d2906a sp bfbbec3c error 7 in libc-2.10.1.so[cb4000+13e000]
3.2 -g
使用gcc编译程序的源码时,加上-g参数,这样可以使得生成的二进制文件中加入可以用于gdb调试的有用信息。以程序2.3为例:
panfeng@ubuntu:~/segfault$ gcc -g -o segfault3 segfault3.c
3.3 nm
使用nm命令列出二进制文件中的符号表,包括符号地址、符号类型、符号名等,这样可以帮助定位在哪里发生了段错误。以程序2.3为例:
panfeng@ubuntu:~/segfault$ nm segfault3
08049f20 d _DYNAMIC
08049ff4 d _GLOBAL_OFFSET_TABLE_
080484dc R _IO_stdin_used
w _Jv_RegisterClasses
08049f10 d __CTOR_END__
08049f0c d __CTOR_LIST__
08049f18 D __DTOR_END__
08049f14 d __DTOR_LIST__
080484ec r __FRAME_END__
08049f1c d __JCR_END__
08049f1c d __JCR_LIST__
0804a014 A __bss_start
0804a00c D __data_start
08048490 t __do_global_ctors_aux
08048360 t __do_global_dtors_aux
0804a010 D __dso_handle
w __gmon_start__
0804848a T __i686.get_pc_thunk.bx
08049f0c d __init_array_end
08049f0c d __init_array_start
08048420 T __libc_csu_fini
08048430 T __libc_csu_init
U __libc_start_main@@GLIBC_2.0
0804a014 A _edata
0804a01c A _end
080484bc T _fini
080484d8 R _fp_hw
080482bc T _init
08048330 T _start
0804a014 b completed.6990
0804a00c W data_start
0804a018 b dtor_idx.6992
080483c0 t frame_mmy
080483e4 T main
U memcpy@@GLIBC_2.0
3.4 ldd
使用ldd命令查看二进制程序的共享链接库依赖,包括库的名称、起始地址,这样可以确定段错误到底是发生在了自己的程序中还是依赖的共享库中。以程序2.3为例:
panfeng@ubuntu:~/segfault$ ldd ./segfault3
linux-gate.so.1 => (0x00e08000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00675000)
/lib/ld-linux.so.2 (0x00482000)
⑧ 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或库里被定义过。