Linux下将可执行文件和so一起发布的技巧
2008-05-23 21:34
627 查看
From Chad Austin ( http://aegisknight.org/ )
One thing I've always liked about Windows is that if you ship an executable
and several DLLs, you just include the DLLs in the same directory as the EXE,
and the loader finds them when the program is loaded. However, the Linux
runtime loader does not search for SOs in the same way. The way most people
work around this (i.e. Mozilla) is by shipping a shell script called 'mozilla'
which sets up LD_LIBRARY_PATH -- enabling the loader to find the right SOs --
and then calling mozilla-bin. It works, but it's pretty hacky.
Well, today, I've found a much better way to do it... Apparently ld.so
expands $ORIGIN in rpath and such to be the location of the executable.
So here's how you specify an rpath relative to the executable:
gcc '-Wl,-rpath=$ORIGIN/bar' -o foo foo.c -Lbar -lbar
Now you can move foo and bar/libbar.so anywhere and they'll still run!
One thing I've always liked about Windows is that if you ship an executable
and several DLLs, you just include the DLLs in the same directory as the EXE,
and the loader finds them when the program is loaded. However, the Linux
runtime loader does not search for SOs in the same way. The way most people
work around this (i.e. Mozilla) is by shipping a shell script called 'mozilla'
which sets up LD_LIBRARY_PATH -- enabling the loader to find the right SOs --
and then calling mozilla-bin. It works, but it's pretty hacky.
Well, today, I've found a much better way to do it... Apparently ld.so
expands $ORIGIN in rpath and such to be the location of the executable.
So here's how you specify an rpath relative to the executable:
gcc '-Wl,-rpath=$ORIGIN/bar' -o foo foo.c -Lbar -lbar
Now you can move foo and bar/libbar.so anywhere and they'll still run!
相关文章推荐
- Linux下查看.so和可执行文件是否debug编译
- Linux下查看.so和可执行文件是否debug编译
- Linux下查看.so和可执行文件是否debug编译的方法(必看)
- Linux下查看.so和可执行文件是否debug编译
- 如何在Linux ELF格式的文件(可执行binary,以及so文件)中定位到对应的函数位置
- Linux下查看.so和可执行文件是否debug编译
- Linux下查看.so和可执行文件是否debug编译
- linux编译出现执行文件找不到相应的so问题
- linux如何查看可执行文件或者so文件的编译器版本
- 收藏一个实用技巧:linux下查看动态链接库so文件的依赖的相关组建发布时间
- linux下发布的执行文件崩溃的问题定位 心得一则
- Linux下的动态链接库.so文件的使用
- linux找不到动态链接库 .so文件的解决方法
- linux下生成.so文件和.a文件
- Linux下执行.sh文件提示No such file or directory
- Linux/shell命令的实际应用——ldd查看可执行程序依赖的库文件
- Linux编译.so文件,调用.so文件
- UNIX/LINUX 平台可执行文件格式分析
- UNIX/LINUX 平台可执行文件格式分析(转)
- linux下动态库so文件的一些认识