- check-rpaths的問題 今天在編譯varnish的時候,遇到幾個問題,其中一個就是出現如下錯誤:...+ /usr/lib/rpm/check-rpaths /usr/lib/rpm/check-buildroot************************************....
- check-rpaths的問題
今天在編譯varnish的時候,遇到幾個問題,其中一個就是出現如下錯誤:
...
+ /usr/lib/rpm/check-rpaths /usr/lib/rpm/check-buildroot ******************************************************************************* * * WARNING: 'check-rpaths' detected a broken RPATH and will cause 'rpmbuild' * to fail. To ignore these errors, you can set the '$QA_RPATHS' * environment variable which is a bitmask allowing the values * below. The current value of QA_RPATHS is 0x0000. * * 0x0001 ... standard RPATHs (e.g. /usr/lib); such RPATHs are a minor * issue but are introducing redundant searchpaths without * providing a benefit. They can also cause errors in multilib * environments. * 0x0002 ... invalid RPATHs; these are RPATHs which are neither absolute * nor relative filenames and can therefore be a SECURITY risk * 0x0004 ... insecure RPATHs; these are relative RPATHs which are a * SECURITY risk * 0x0008 ... the special '$ORIGIN' RPATHs are appearing after other * RPATHs; this is just a minor issue but usually unwanted * 0x0010 ... the RPATH is empty; there is no reason for such RPATHs * and they cause unneeded work while loading libraries * 0x0020 ... an RPATH references '..' of an absolute path; this will break * the functionality when the path before '..' is a symlink * * * Examples: * - to ignore standard and empty RPATHs, execute 'rpmbuild' like * $ QA_RPATHS=$[ 0x0001|0x0010 ] rpmbuild my-package.src.rpm * - to check existing files, set $RPM_BUILD_ROOT and execute check-rpaths like * $ RPM_BUILD_ROOT=<top-dir> /usr/lib/rpm/check-rpaths * ******************************************************************************* ERROR 0002: file 'xxx.so' contains an invalid rpath 'xxx' in [xxx]
...
參考 https://fedoraproject.org/wiki/Packaging:Guidelines, 其中說道:
Sometimes, code will hardcode specific library paths when linking binaries (using the -rpath or -R flag). This is commonly referred to as an rpath. Normally, the dynamic linker and loader (ld.so) resolve the executable's dependencies on shared libraries and load what is required. However, when -rpath or -R is used, the location information is then hardcoded into the binary and is examined by ld.so in the beginning of the execution. Since the Linux dynamic linker is usually smarter than a hardcoded path, we usually do not permit the use of rpath in Fedora. There is a tool called check-rpaths which is included in the rpmdevtools package. It is a good idea to add it to the %__arch_install_post macro in your ~/.rpmmacros config file:
由此可知,這一步只是一種檢測是不是代碼中使用了rpath,那我們可以簡單的註釋掉rpath檢測就可以了,具體做法就是:
vi ~/.rpmmacros
%_topdir %(echo $HOME)/rpmbuild %_smp_mflags -j3 #%__arch_install_post /usr/lib/rpm/check-rpaths /usr/lib/rpm/check-buildroot
後面就能順利編譯了
- pkgconfig跟ldconfig, ldd的問題
先看下麵的說明:
1. The pkgconfig package contains tools for passing the include path and/or library paths to build tools during the make file execution.
pkg-config is a function that returns meta information for the specified library.
The default setting for PKG_CONFIG_PATH is /usr/lib/pkgconfig because of the prefix we use to install pkgconfig. You may add to PKG_CONFIG_PATH by exporting additional paths on your system where pkgconfig files are installed. Note that PKG_CONFIG_PATH is only needed when compiling packages, not during run-time.
上面的解釋夠清楚了,pkg-config是用來在執行makefile時指定頭文件和庫文件的路徑。它到由環境變數PKG_CONFIG_PATH指定的路徑下(預設為/usr/lib/config)去找對應庫的*.pc文件,*.pc文件記錄了包之間的倚賴關係、頭文件和庫文件包含路徑、版本等信息。
2. /etc/ld.so.conf.d/* 或/etc/ld.so.conf和ldconfig.
/etc/ld.so.conf.d/*目錄下的文件和/etc/ld.so.conf記錄了動態鏈接庫的路徑,系統預設搜索/lib和 /usr/lib,在其他路徑下的庫文件就需在這些文件中指定。或者,還有個方法,就是設置LD_LIBRARY_PATH環境變數,添加其他路徑,多個 中間用:分隔開。
ldconfig是一個用來將/etc/ld.so.conf.d/*h 和/etc/ld.so.conf中列出的庫緩存到/etc/ld.so.cache文件中以供使用,因此在裝完一些庫或更新/etc/ld.so.conf文件時,需運行/sbin/ldconfig命令一下。
當運行 ./configure 產生Makefile的過程中出現, pkg-config有問題,或是不能找到對應的lib文件的時候。
不妨重新設置下pkgconfig的兩個變數:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/share/pkgconfig:$PKG_CONFIG_PATH
export PKG_CONFIG=/usr/bin/pkg-config
並且重新載入下動態鏈接庫
ldconfig
另外一個非常實用的調試腳本就是ldd:
[root@xx pcre-8.34]# ldd /bin/ls linux-vdso.so.1 => (0x00007fff2a5ff000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fec45edf000) librt.so.1 => /lib64/librt.so.1 (0x00007fec45cd7000) libcap.so.2 => /lib64/libcap.so.2 (0x00007fec45ad2000) libacl.so.1 => /lib64/libacl.so.1 (0x00007fec458ca000) libc.so.6 => /lib64/libc.so.6 (0x00007fec45536000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fec45331000) /lib64/ld-linux-x86-64.so.2 (0x00007fec46105000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fec45114000) libattr.so.1 => /lib64/libattr.so.1 (0x00007fec44f0f000) [root@xx pcre-8.34]#
其本質也就是設置諸如LD_DEBUG等環境變數,在程式運行時,列印出調用的動態鏈接庫。