在进行交叉编译的时候,出现 “not found (try using -rpath or -rpath-link)” 错误,可能是由于没有设置sysroot,而使用了rpath进行运行库的搜索路径指定,导致在链接的时候找不到对应的动态库。可以使用rpath-link来替代rpath参数。
larchive
--library=archiveAdd archive file archive to the list of files to link. This option may be used any number of times.
ldwill search its path-list for occurrences oflibarchive.afor every archive specified. On systems which support shared libraries,ldmay also search for libraries with extensions other than.a. Specifically, on ELF and SunOS systems,ldwill search a directory for a library with an extension of.sobefore searching for one with an extension of.a. By convention, a.soextension indicates a shared library. The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again. See the-(option for a way to force the linker to search archives multiple times. You may list the same archive multiple times on the command line. This type of archive searching is standard for Unix linkers. However, if you are usingldon AIX, note that it is different from the behaviour of the AIX linker.
-Lsearchdir
--library-path=searchdirAdd path searchdir to the list of paths that
ldwill search for archive libraries andldcontrol scripts. You may use this option any number of times. The directories are searched in the order in which they are specified on the command line. Directories specified on the command line are searched before the default directories. All-Loptions apply to all-loptions, regardless of the order in which the options appear. The default set of paths searched (without being specified with `-L') depends on which emulation modeldis using, and in some cases also on how it was configured. See section Environment Variables. The paths can also be specified in a link script with theSEARCH_DIRcommand. Directories specified this way are searched at the point in which the linker script appears in the command line.
--sysroot=dirUse dir as the logical root directory for headers and libraries. For example, if the compiler normally searches for headers in /usr/include and libraries in /usr/lib, it instead searches dir/usr/include and dir/usr/lib.
If you use both this option and the -isysroot option, then the --sysroot option applies to libraries, but the -isysroot option applies to header files.
The GNU linker (beginning with version 2.16) has the necessary support for this option. If your linker does not support this option, the header file aspect of --sysroot still works, but the library aspect does not.
-rpath dirAdd a directory to the runtime library search path. This is used when linking an ELF executable with shared objects. All
-rpatharguments are concatenated and passed to the runtime linker, which uses them to locate shared objects at runtime. The-rpathoption is also used when locating shared objects which are needed by shared objects explicitly included in the link; see the description of the-rpath-linkoption. If-rpathis not used when linking an ELF executable, the contents of the environment variableLD_RUN_PATHwill be used if it is defined. The-rpathoption may also be used on SunOS. By default, on SunOS, the linker will form a runtime search patch out of all the-Loptions it is given. If a-rpathoption is used, the runtime search path will be formed exclusively using the-rpathoptions, ignoring the-Loptions. This can be useful when using gcc, which adds many-Loptions which may be on NFS mounted filesystems. For compatibility with other ELF linkers, if the-Roption is followed by a directory name, rather than a file name, it is treated as the-rpathoption.
-rpath-link DIR
When using ELF or SunOS, one shared library may require another. This happens when an ld -shared link includes a shared library as one of the input files. When the linker encounters such a dependency when doing a non-shared, non-relocateable link, it will automatically try to locate the required shared library and include it in the link, if it is not included explicitly. In such a case, the -rpath-link option specifies the first set of directories to search. The -rpath-link option may specify a sequence of directory names either by specifying a list of names separated by colons, or by appearing multiple times. The linker uses the following search paths to locate required shared libraries.
Any directories specified by -rpath-link options.
Any directories specified by -rpath options. The difference between -rpath and -rpath-link is that directories specified by -rpath options are included in the executable and used at runtime, whereas the -rpath-link option is only effective at link time.
On an ELF system, if the -rpath and rpath-link options were not used, search the contents of the environment variable LD_RUN_PATH.
On SunOS, if the -rpath option was not used, search any directories specified using -L options.
For a native linker, the contents of the environment variable LD_LIBRARY_PATH.
The default directories, normally `/lib' and `/usr/lib'.