ld搜索格式错误的目录路径 [英] ld searching malformed directory paths

查看:121
本文介绍了ld搜索格式错误的目录路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ld链接到文件系统上的库.

I'm linking to a library on my filesystem using ld.

运行命令ld -verbose -lmylib时,我得到以下信息:

When I run the command ld -verbose -lmylib, I get the following back:

attempt to open /usr/x86_64-linux-gnu/lib64/libmylib.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/libmylib.a failed
attempt to open //usr/local/lib/x86_64-linux-gnu/libmylib.so failed
attempt to open //usr/local/lib/x86_64-linux-gnu/libmylib.a failed
attempt to open //usr/local/lib64/libmylib.so failed
attempt to open //usr/local/lib64/libmylib.a failed
attempt to open //lib/x86_64-linux-gnu/libmylib.so failed
attempt to open //lib/x86_64-linux-gnu/libmylib.a failed
attempt to open //lib64/libmylib.so failed
attempt to open //lib64/libmylib.a failed
attempt to open //usr/lib/x86_64-linux-gnu/libmylib.so failed
attempt to open //usr/lib/x86_64-linux-gnu/libmylib.a failed
attempt to open //usr/lib64/libmylib.so failed
attempt to open //usr/lib64/libmylib.a failed
attempt to open //usr/local/lib/libmylib.so failed
attempt to open //usr/local/lib/libmylib.a failed
attempt to open //lib/libmylib.so failed
attempt to open //lib/libmylib.a failed
attempt to open //usr/lib/libmylib.so failed
attempt to open //usr/lib/libmylib.a failed
ld: cannot find -lmylib

对于为什么要打开以//为前缀的文件,我感到困惑.我的另一台计算机不是这种情况.我尝试更改LIBRARY_PATHLD_LIBRARY_PATH,我的PATH等,但似乎无济于事.我在网上看过,但找不到任何东西.这些路径在哪里设置?

I'm confused as to why it's trying to open files prefixed with //. This is not the case for another computer of mine. I've tried changing LIBRARY_PATH, LD_LIBRARY_PATH, my PATH, etc. but nothing seems to work. I've looked online, but can't find anything. Where are these paths set?

谢谢.

推荐答案

此处的问题是您尝试链接库mylib,但是该库不在系统的库搜索路径中,或者它不存在完全没有.您请确保将其放置在正确的位置.如果该库位于不在库搜索路径中的另一个目录中,则可以使用-L选项将其添加到ld,例如ld -verbose -L<the directory> -lmylib.

The problem here is you are trying to link against the library mylib, but this library is not in the system's library search path, or it does not exists at all. You please make it locate at the right place. If the library is in another directory that is not in the library search path, you can add it with -L option to ld, like ld -verbose -L<the directory> -lmylib.

对于您看到的双斜杠,这不是问题,因为在Linux上,更多的斜杠被解释为一个斜杠,也就是说,//foo/bar与/foo/bar相同,所以不要不必担心.

As for the double slash you see, it's not a problem, as more than more slashes are interpreted as one slash on Linux, that is to say, //foo/bar is the same as /foo/bar`, so don't need to worry about it.

关于搜索路径的差异,在Fedora上,默认搜索路径为:

As for the difference of the search path, on Fedora, the default search path is:

SEARCH_DIR("/usr/x86_64-redhat-linux/lib64"); SEARCH_DIR("/usr/lib64"); SEARCH_DIR("/usr/local/lib64"); SEARCH_DIR("/lib64"); SEARCH_DIR("/usr/x86_64-redhat-linux/lib"); SEARCH_DIR("/usr/local/lib"); SEARCH_DIR("/lib"); SEARCH_DIR("/usr/lib");

在Ubuntu上,它是:

While on Ubuntu, it is:

SEARCH_DIR("/usr/x86_64-linux-gnu/lib64"); SEARCH_DIR("=/usr/local/lib/x86_64-linux-gnu"); SEARCH_DIR("=/usr/local/lib64"); SEARCH_DIR("=/lib/x86_64-linux-gnu"); SEARCH_DIR("=/lib64"); SEARCH_DIR("=/usr/lib/x86_64-linux-gnu"); SEARCH_DIR("=/usr/lib64"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");

因此,Ubuntu以前缀"="开始每个路径,现在让我们看看ld为此做什么:

So Ubuntu start each path with prefix '=', now let's see what ld does for this:

如果searchdir以"="开头,则"="将由sysroot前缀替换,由--sysroot选项控制,或者在配置链接器时指定.

If searchdir begins with "=", then the "=" will be replaced by the sysroot prefix, controlled by the --sysroot option, or specified when the linker is configured.

这意味着=将被系统根目录代替,对于Linux系统,最像是/.这就是为什么您在Ubuntu而不是Fedora上看到双斜杠的原因.

That means = will be replaced by system root, which most like is / for a Linux system. That's why you see the double slashes on Ubuntu not on Fedora.

这篇关于ld搜索格式错误的目录路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆