您的位置:首页 > 运维架构 > Linux

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根本不起作用,所有用非标准路径的话必需手动指定库目录
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: