使用场景
在进行交叉编译的时候,出现 “not found (try using -rpath or -rpath-link)” 错误,可能是由于没有设置sysroot,而使用了rpath进行运行库的搜索路径指定,导致在链接的时候找不到对应的动态库。可以使用rpath-link来替代rpath参数。
一、使用说明
- -l 就是表示添加需要链接的库文件,如果没有用后缀指明动态库还是静态库,则优先使用动态库。
- -L 就是添加链接库的搜索目录,可以看成是为-l服务的。
- --sysroot = dir 将dir作为逻辑root目录,用于搜索头文件和依赖库文件,例如--sysroot=/home/build,那么如果之前默认去/usr/lib下面去搜索依赖库,则在sysroot的作用下会定位到/home/build/usr/lib目录下进行搜索。这个参数在交叉编译的时候会影响到rpath,如果没有设置这个sysroot,则rpath在编译阶段是不起作用的。
- -rpath = dir 这个参数在编译可执行文件的时候,用来指定运行库的搜索目录,该目录会被记录在elf可执行文件中。与此同时在链接阶段,也可以兼职-rpath-link的功能,作为编译时动态库的搜索路径。但是如果启用了该参数,-L参数就会失效。在交叉编译环境中,该参数需要同sysroot共同作用,如没有sysroot则该参数会部分失效,无法将dir添加进链接库的搜索路径列表中,最终导致“ not found (try using -rpath or -rpath-link)” 错误提示。
- -rpath-link 这个参数类似rpath,提供运行库的搜索路径,但是该参数只是在链接阶段起作用,不会被写入elf文件中。
二、官方手册
- -l 的解释
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 c

本文详细解释了在进行交叉编译时遇到notfound错误的常见原因,重点讲解了sysroot的作用以及如何正确设置rpath和rpath-link参数以确保动态库的查找。
最低0.47元/天 解锁文章
610

被折叠的 条评论
为什么被折叠?



