ld searching malformed directory paths

前端 未结 1 974
挽巷
挽巷 2021-01-23 00:09

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

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

atte         


        
相关标签:
1条回答
  • 2021-01-23 00:45

    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.

    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.

    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");
    

    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");
    

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

    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.

    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.

    0 讨论(0)
提交回复
热议问题