ldd  查看 elf文件依赖的  so 动态链接库

可以  export

LD_LIBRARY_PATH=/path 设置 so文件的路径,

nm  -u  *.so  或者 nm

|grep  U 查看

那些在  动态链接库中的符号。

"U" The symbol is undefinedundefined的 symbol

这种就是表示 在其他 so动态链接库里面定义的。但是如果你的编译的

是so文件,如果符号不在外部任何so文件里面,默认的配置也不会提示错误。而是编译通过。那个自己忘了定义的符号也在 这

undefined

symbol里面,但是运行时就加载不成功了。

文档说,这种编译so动态链接库时找不到符号(不在任何外部so文件里面,自己的程序也没有定义)也允许编译通过是有原因的,参见

ld 的man 说明  --allow-shlib-un

更多来源:http://www.zgjx114.com

defined 解释(好像英文版的才完整,中文的man ld不完整 可以直接查看网页

https://sourceware.org/binutils/docs-2.24/ld/Options.html#Options

)。就是让你链接时用的一个版本的so,运行时加载用的另外一个版本的so,可能你的加载时的so里面有这个符号,所以就先让你找不到符号也编译通过了。如果是编译exe,这中链接时找不到定义的符号的就直接给你报错了。

so动态链接库就不会报错。其实这种特性应该是比较少用,最好在so链接是碰到这个未找到的符号也是报错的好。

所以我觉得编译的动态链接库的时候最好加上

--unresolved-symbols=ignore-in-shared-libs  或者

--no-undefined 来检查一下。这样如果是自己的疏忽在 .c 源文件里面忘记的

某函数的定义,,编译的时候就可以提示错误了。

这里有3个参数可以使用--undefined symbols

和 --no-allow-shlib-undefined

参数的作用范围不一样而已,--undefined symbols

针对常规object文件,--no-allow-shlib-undefined针对的是符号在外部的未定义的shared

object里面。--unresolved-symbols和--undefined symbols

作用差不多,不过更具体一些。

我们的目的主要是编译一个so动态链接库时,把自己object里面未定义的符号report出来就可以了,用--no-undefined和--unresolved-symbols=ignore-in-shared-libs应该可以的。

ld  的参数,  如果直接用gcc 编译,可以用

-Wl,--no-undefined 这样传过去

gcc -shared -Wl,-soname,libb.so.1,--no-undefined -o libb.so.1.2

objectfile

gcc -shared

-Wl,-soname,libb.so.1,--unresolved-symbols=ignore-in-shared-libs

-o libb.so.1.2  objectfile

---------------------------------------

--no-undefined-z defsReport unresolved symbol references from

regular object files. This is done even if the linker is creating a

non-symbolic shared library. The

switch --[no-]allow-shlib-undefined controls

the behaviour for reporting unresolved references found in shared

libraries being linked in.

----------------------------

--unresolved-symbols=method

Determine how to handle unresolved symbols. There are four

possible values for

`method':`ignore-all'Do not report

any unresolved symbols. `report-all'Report all unresolved symbols. This is

the default. `ignore-in-object-files'Report unresolved symbols

that are contained in shared libraries, but ignore them if they

come from regular object files. `ignore-in-shared-libs'Report unresolved symbols

that come from regular object files, but ignore them if they come

from shared libraries. This can be useful when creating a dynamic

binary and it is known that all the shared libraries that it should

be referencing are included on the linker's command

line.

The behaviour for shared libraries on

their own can also be controlled by

the --[no-]allow-shlib-undefined option.

Normally the linker will generate an

error message for each reported unresolved symbol but the

option --warn-unresolved-symbols can

change this to a warning.

-----------------------------

-static

Do not link

against shared libraries.  This is only meaningful

on

platforms

for which shared libraries are supported.  The

different

variants of

this option are for compatibility with various systems.

You may use

this option multiple times on the command line: it

affects

library searching for -l options which follow it.

This

option also

implies --unresolved-symbols=report-all.  This

option

can be used

with -shared.  Doing so means that a shared

library is

being

created but that all of the library's external

references

must be

resolved by pulling in entries from static libraries.

--allow-shlib-undefined

--no-allow-shlib-undefinedAllows or disallows undefined symbols

in shared libraries. This switch is similar

to --no-undefined except that it

determines the behaviour when the undefined symbols are in a shared

library rather than a regular object file. It does not affect how

undefined symbols in regular object files are handled.

The default behaviour is to report

errors for any undefined symbols referenced in shared libraries if

the linker is being used to create an executable, but to allow them

if the linker is being used to create a shared library.

The reasons for allowing undefined

symbol references in shared libraries specified at link time are

that:

A shared library specified at link time may not be the same as

the one that is available at load time, so the symbol might

actually be resolvable at load time.

There are some operating systems, eg BeOS and HPPA, where

undefined symbols in shared libraries are normal.

The BeOS kernel for example patches shared libraries at load

time to select whichever function is most appropriate for the

current architecture. This is used, for example, to dynamically

select an appropriate memset function.

linux编译动态库未定义,linux 编译动态链接库 so,避免运行时才发现函数未 ......相关推荐

  1. linux下动态库符号表,Linux动态库(.so)符号表

    最近编译libbinder.so发现system/lib/libbinder.so只有358K,但单独编译生成的obj/SHARED_LIBRARIES/libbinder_intermediates ...

  2. linux c 如何编译静态库,Linux C 编程入门之一:gcc 编译动态库和静态库

    主调用程序源代码3-1:main.c /** * main.c */ #include #include #include "hello_fn.h" int main () { h ...

  3. Linux:编译动态库时遇到的错误relocation R_X86_64_32 against `a local symbol'

    编译动态库时遇到如下错误: ... ... relocation R_X86_64_32 against `a local symbol' can not be used when making a ...

  4. Linux环境编译动态库和静态库总结

    首先总结静态库的编译步骤. 1 先基于.cpp或者.c文件生成对应的.o文件 2将几个.o文件 使用ar -cr命令 生成libname.a文件 libname.a 为静态库, name 为静态库的名 ...

  5. linux安装了xml怎么编译,linux下libxml库的安装及编译

    linux下libxml库的安装及编译 1. 下载和安装LIBXML2 Libxml2是个C语言的XML程式库,能简单方便的提供对XML文件的各种操作,并且支持XPATH查询,及部分的支持XSLT转换 ...

  6. linux 调用动态库so文件

    关于动态调用动态库方法说明 一.        动态库概述 1.  动态库的概念 日常编程中,常有一些函数不需要进行编译或者可以在多个文件中使用(如数据库输入/输出操作或屏幕控制等标准任务函数).可以 ...

  7. linux查看动态库导出的符号,Linux下控制动态库导出

    在Linux中动态库的确给程序带来了良好的扩充性,并减少了内存的使用量,但这是有代价的.例如: #include Int main(int argc, char *argv[]) { Printf(& ...

  8. linux 动态库建立,浅析linux下静态库和动态库的建立和使用

    在粤嵌学了很多知识,我们把常用的公用函数放在一起做成一个函数库,可以供其他程序共同使用,函数库本质上说,是一个可执行代码的二进制形式,可被操作系统载入内存执行.linux下的库分为两种:静态库,后缀名 ...

  9. g++ 编译mysql动态库_Linux下g++编译以及使用静态库和动态库的方法详解

    下面小编就为大家带来一篇Linux下g++编译与使用静态库和动态库的方法.小编觉得挺不错的,现在就分享给大家,也给大家做个参考.一起跟随小编过来看看吧 在windows环境下,我们通常在IDE如VS的 ...

最新文章

  1. 《科学》:中国科学家揭示,人脑中间神经元多样性从何而来?
  2. web开发下的各种下载方法
  3. 【精华】Linux用户Hive权限控制实践
  4. UVALive 3942 Remember the Word(字典树+DP)
  5. 魅族升级android p,高通宣布:这些手机将第一时间升级Android P!
  6. excel loc() python_总结:像Excel一样使用python进行数据分析
  7. F - Parenthesis Checking
  8. ubuntu安装matlab2016b
  9. 好课堂Scratch编程09 趣学篇(五)目标!幽灵古堡
  10. 给变量取个名字(变量命名)
  11. 对javaWeb理解
  12. 没有 本地计算机策略组,win10家庭版没有本地组策略编辑器怎么办
  13. 命令行执行 mvn package 和常见mvn命令
  14. pandas入门(6)——数据加载、存储与文件格式
  15. java财务管理源代码_java 个人财务管理系统 入门级源码
  16. 程序员 PK 刘畊宏 | 我用代码实现刘畊宏龙拳
  17. cesium 根据经纬度与距离计算另一个经纬度
  18. 一:移动端UI框架mint-ui
  19. .net 打开服务器文档,net 网络
  20. ide怎么设置方法中间加一道横线_苹果手机怎么录屏_iPhone如何录屏_iOS录屏方法...

热门文章

  1. GlusterFS-FUSE
  2. 各位最近找我索要CCNA200-120的资源的同志些
  3. 如何用Powerdesigner的PDM(物理数据模型)生成数据库及逆向工程(将现有的数据库生成PDM)(转)...
  4. 在拓扑图上做标准ACL和扩展ACL(期末考试)
  5. IP地址不够了,有办法吗?
  6. HTML5圆形线性渐变,css中linear-gradient()函数是干什么的?实现线性渐变的圆形边框(代码)...
  7. java 枚举 循环_java – 在枚举中实现内部接口时的循环继承
  8. mysql增加字段默认位置_MySQL语句增加字段,修改字段名,修改类型,修改默认值
  9. python设置画布背景图_如何使画布中的背景图像随窗口展开?
  10. 我的世界java版幻翼_我的世界:熬夜3天能见到“幻翼”?你错了,还要满足这7个条件!...