shared library search path set on linux
2013-01-30 15:17
169 查看
1. first way
1.1 add relative lib path to /etc/ld.so.conf, for example
include /etc/ld.so.conf.d/*.conf
/lib
/usr/lib
/usr/local/lib
1.2. run command ldconfig
2. second way
LOCAL_EXTRA_CFLAGS="-I/usr/local/x264/include"
LOCAL_LD_FLAGS="-L/usr/local/x264/lib"
cd ffmpeg-1.1.1
make clean
./configure --prefix=/usr/local/ffmpeg-1.1.1 \
--enable-version3 \
--enable-gpl --enable-pthreads \
--enable-avfilter \
--enable-shared \
--disable-encoders \
--disable-decoders \
--enable-libx264 \
--enable-encoder=rawvideo \
--enable-decoder=rawvideo \
--enable-encoder=libx264 \
--enable-debug --enable-nonfree \
--disable-postproc \
--disable-ffserver --disable-ffplay \
--disable-stripping \
--extra-cflags="$LOCAL_EXTRA_CFLAGS" \
--extra-ldflags="$LOCAL_LD_FLAGS"
make
make install
附:
设置了/etc/ld.so.conf,运行了ldconfig,编译仍找不到动态库
我的makefile文件如下:
test:test.o
gcc test.o -ldl -lsmbios -o test
test.o:test.c
gcc -c test.c -o test.o
动态库在/home/lib-jar/test中,我配置了/etc/ld.so.conf
/etc/ld.so.conf内容如下:
include ld.so.conf.d/*.conf
/home/lib-jar/test
然后执行了ldconfig命令,
执行ldconfig -p也能找到动态库
[root@zhaozhanzhong test]# ldconfig -p | grep smbios
libsmbios.so (libc6,x86-64) => /home/lib-jar/test/libsmbios.so
可执行make,却出错,结果如下
[root@zhaozhanzhong test]# make
gcc -c test.c -o test.o
gcc test.o -ldl -lsmbios -o test
/usr/bin/ld: cannot find -lsmbios
collect2: ld returned 1 exit status
make: *** [test] Error 1
但是当我把libsmbios.so拷贝到/usr/lib目录下时就没问题
请问这是怎么回事
------解决方案--------------------------------------------------------
你理解错了,ld.so是动态库载入器而不是连接器,某些翻译“动态连接器”有问题的,或者说英文原文就有问题
换句话说,配置ld.so.conf的作用就是如果so在非标准路径,可执行文件能够找到,这是运行期做的事情
你现在是编译,ld.so根本不起作用,所有用非标准路径的话必需手动指定库目录
1.1 add relative lib path to /etc/ld.so.conf, for example
include /etc/ld.so.conf.d/*.conf
/lib
/usr/lib
/usr/local/lib
1.2. run command ldconfig
2. second way
LOCAL_EXTRA_CFLAGS="-I/usr/local/x264/include"
LOCAL_LD_FLAGS="-L/usr/local/x264/lib"
cd ffmpeg-1.1.1
make clean
./configure --prefix=/usr/local/ffmpeg-1.1.1 \
--enable-version3 \
--enable-gpl --enable-pthreads \
--enable-avfilter \
--enable-shared \
--disable-encoders \
--disable-decoders \
--enable-libx264 \
--enable-encoder=rawvideo \
--enable-decoder=rawvideo \
--enable-encoder=libx264 \
--enable-debug --enable-nonfree \
--disable-postproc \
--disable-ffserver --disable-ffplay \
--disable-stripping \
--extra-cflags="$LOCAL_EXTRA_CFLAGS" \
--extra-ldflags="$LOCAL_LD_FLAGS"
make
make install
附:
设置了/etc/ld.so.conf,运行了ldconfig,编译仍找不到动态库
我的makefile文件如下:
test:test.o
gcc test.o -ldl -lsmbios -o test
test.o:test.c
gcc -c test.c -o test.o
动态库在/home/lib-jar/test中,我配置了/etc/ld.so.conf
/etc/ld.so.conf内容如下:
include ld.so.conf.d/*.conf
/home/lib-jar/test
然后执行了ldconfig命令,
执行ldconfig -p也能找到动态库
[root@zhaozhanzhong test]# ldconfig -p | grep smbios
libsmbios.so (libc6,x86-64) => /home/lib-jar/test/libsmbios.so
可执行make,却出错,结果如下
[root@zhaozhanzhong test]# make
gcc -c test.c -o test.o
gcc test.o -ldl -lsmbios -o test
/usr/bin/ld: cannot find -lsmbios
collect2: ld returned 1 exit status
make: *** [test] Error 1
但是当我把libsmbios.so拷贝到/usr/lib目录下时就没问题
请问这是怎么回事
------解决方案--------------------------------------------------------
你理解错了,ld.so是动态库载入器而不是连接器,某些翻译“动态连接器”有问题的,或者说英文原文就有问题
换句话说,配置ld.so.conf的作用就是如果so在非标准路径,可执行文件能够找到,这是运行期做的事情
你现在是编译,ld.so根本不起作用,所有用非标准路径的话必需手动指定库目录
相关文章推荐
- Shared Library Search Paths On Linux
- 解决Visual C++ for Linux: -L"~/projects/path_to_lib_folder" 无法设置library search path的问题
- Set up Shared Screen on Linux
- How to Set Classpath for Java on Windows and Linux
- Linux: Set OR Change The Library Path
- 设置 Linux 的 LD_LIBRARY_PATH 变量
- Sample Code on Linux semaphore and shared memory
- 设置 Linux 的 LD_LIBRARY_PATH 路径
- linux安装mysql出现Could NOT find Curses (missing CURSES_LIBRARY CURSES_INCLUDE_PATH),提示解决方法
- The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path:
- linux环境变量设置方法总结(PATH/LD_LIBRARY_PATH)
- Could not load 'clearsilver-jni' java.library.path = out/host/linux-x86/lib make: *** [out/target/common/docs/api-stubs-timestam
- boost c++ library on linux 初体验
- set_include_path在win和linux下的区别
- How to Set Up an Rsync Daemon on Your Linux Server
- Linux 共享库: LD_LIBRARY_PATH 与ld.so.conf
- 设置 Linux 的 LD_LIBRARY_PATH 变量
- 解决 The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path
- linux 环境变量设置方法总结(PATH / LD_LIBRARY_PATH)
- linux共享库位置配置(LD_LIBRARY_PATH环境变量 或者 更改/etc/ld.so.conf 或者 使用-R选项)