动态链接:链接路径的更改

Normally it happens that when ever the path of the library that has to be linked dynamically is defined in LD_LIBRARY_PATH or it it will be mentioned with -L flag while creating the binary.

In actual scenario if ,lets say the binary has been built and deployed at the client place. Now if there is a change in the path of one of the dynamic link library path. then we need to supply a new make file to all the clients where the binary was deployed.

is there any other method where we need not tell all the clients to change their makefiles and can something can be done in the code itself? if yes...could anybody please suggest how?

This was ironically an interview question that was asked to me and i didnot have the answer for it.

EDIT:: I was specifically asked about what can be done in the code without touching the makefile.

#0

Usually you should only change the LD_LIBRARY_PATH, unless this might be related to a compilation with a hard-coded search path: rpath.

#1

Use environment variable, like MYLIBPATH, and use this variable in your makefile, rather than hard-coded value.

So every client can have own directory structure, and as long as they correctly specify MYLIBPATH, your program builds ok.

Alternatively you can look for library in your makefile, like this

LIBPATH = $(shell find / -name libmylib.a -exec dirname {} ";" -quit)

myprog: myprog.c
        $(CC) myprog.c -lmylib -L$(LIBPATH)

EDIT: locate replaced with find that returns just first match with -quit option

#2

Maybe the interviewers wanted to know about dlopen and dlsym? http://linux.die.net/man/3/dlsym

推荐文章

OSX沙盒中的非就地保存

OSX沙盒中的非就地保存

推荐文章

addview的位置常数是多少

addview的位置常数是多少

推荐文章

如何测试httpjson服务器的性能?

如何测试httpjson服务器的性能?

推荐文章

解弦时遇到的问题

解弦时遇到的问题

推荐文章

忽略prettyfaces模式中的大小写

忽略prettyfaces模式中的大小写

推荐文章

在Linux中禁用vsyscalls

在Linux中禁用vsyscalls

推荐文章

c++结构是否有默认构造函数?

c++结构是否有默认构造函数?

推荐文章

在中以编程方式访问窗体htmlasp.net?

在中以编程方式访问窗体htmlasp.net?

推荐文章

如何跳过打开/关闭范围模式的记录?

如何跳过打开/关闭范围模式的记录?

推荐文章

sed只替换搜索字符串中的匹配部分

sed只替换搜索字符串中的匹配部分

推荐文章

做什么PorterDuff.模式android中的平均值图形。什么是吗?

做什么PorterDuff.模式android中的平均值图形。什么是吗?

推荐文章

在应用程序菜单中找不到我的第一个应用程序。安卓

在应用程序菜单中找不到我的第一个应用程序。安卓

推荐文章

android意图给出nullpointer异常

android意图给出nullpointer异常

推荐文章

我的服务没有人打电话

我的服务没有人打电话

推荐文章

应用调度器和控制调度器

应用调度器和控制调度器

推荐文章

在Internet Explorer中,将元素垂直居中于另一个元素中

在Internet Explorer中,将元素垂直居中于另一个元素中