免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1954 | 回复: 5
打印 上一主题 下一主题

[C] C专家编程上的一个疑问 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-10-19 21:57 |只看该作者 |倒序浏览
C专家编程第五章,对链接的思考,P97有这样一段话:
-L/home/linden 和 -R/home/linden选项分别告诉链接器在链接时和运行时从哪个目录寻找需要链接的函数库。

当时看到这句话的时候,觉得这两个参数有一个是多余的。请问这个-R选项有什么用?
另外从网上查到用gcc编译和书上编译方式也不一样 gcc - o test test.c -L. -lfruit
这样的话进一步说明了不需要-R选项。是这样的么?

论坛徽章:
5
狮子座
日期:2013-08-20 10:12:24午马
日期:2013-11-23 18:04:102015年辞旧岁徽章
日期:2015-03-03 16:54:152015亚冠之德黑兰石油
日期:2015-06-29 18:11:1115-16赛季CBA联赛之新疆
日期:2024-02-21 10:00:53
2 [报告]
发表于 2010-10-19 22:47 |只看该作者
孩子,知道世界上有个东西叫做动态链接库么?

论坛徽章:
0
3 [报告]
发表于 2010-10-20 09:42 |只看该作者
-L path
           Adds  path  to  the  library  search  directories.  ld
           searches for libraries first in any directories speci-
           fied by the -L options and then in the standard direc-
           tories.  This option is useful only if it precedes the
           -l options to which it applies on  the  command  line.
           The  environment  variable LD_LIBRARY_PATH may be used
           to   supplement   the   library   search   path   (see
           LD_LIBRARY_PATH below).

     -R path
           A colon-separated list of directories used to  specify
           library  search  directories to the runtime linker. If
           present and not NULL, it is  recorded  in  the  output
           object file and passed to the runtime linker. Multiple
           instances of this  option  are  concatenated  together
           with each path separated by a colon.


-L是表示在链接时候查找链接库的路径。
-R是表示在运行时候加载链接库的路径。

论坛徽章:
1
CU十二周年纪念徽章
日期:2013-10-24 15:41:34
4 [报告]
发表于 2010-10-20 10:04 |只看该作者
是可以不用-R选项的,在运行时查找动态库有很多方法,比如ld.so.conf等。

论坛徽章:
3
巳蛇
日期:2013-10-03 10:41:48申猴
日期:2014-07-29 16:12:04天蝎座
日期:2014-08-21 09:24:52
5 [报告]
发表于 2010-10-20 10:49 |只看该作者
不加-R也可以。
把生成的动态库拷到/usr/lib下面也可以。{:3_199:}

论坛徽章:
0
6 [报告]
发表于 2010-10-20 10:58 |只看该作者
如果你相让一个程序动态运行的时候去你指定的地方查找库  就要用到-R了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP