usr/bin/ld: cannot find -l

前端 未结 14 2682
离开以前
离开以前 2020-11-22 07:07

I\'m trying to compile my program and it returns this error :

usr/bin/ld: cannot find -l

in my makefile I use the c

相关标签:
14条回答
  • 2020-11-22 07:47

    Check the location of your library, for example lxxx.so:

    locate lxxx.so
    

    If it is not in the /usr/lib folder, type this:

    sudo cp yourpath/lxxx.so /usr/lib
    

    Done.

    0 讨论(0)
  • 2020-11-22 07:48

    Here is Ubuntu information of my laptop.

    lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 18.04.2 LTS
    Release:    18.04
    Codename:   bionic
    

    I use locate to find the .so files for boost_filesystem and boost_system

    locate libboost_filesystem
    locate libboost_system
    

    Then link .so files to /usr/lib and rename to .so

    sudo ln -s /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.65.1 /usr/lib/libboost_filesystem.so
    sudo ln -s /usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1 /usr/lib/libboost_system.so
    

    Done! R package velocyto.R was successfully installed!

    0 讨论(0)
  • 2020-11-22 07:49

    Apart from the answers already given, it may also be the case that the *.so file exists but is not named properly. Or it may be the case that *.so file exists but it is owned by another user / root.

    Issue 1: Improper name

    If you are linking the file as -l<nameOfLibrary> then library file name MUST be of the form lib<nameOfLibrary> If you only have <nameOfLibrary>.so file, rename it!

    Issue 2: Wrong owner

    To verify that this is not the problem - do

    ls -l /path/to/.so/file
    

    If the file is owned by root or another user, you need to do

    sudo chown yourUserName:yourUserName /path/to/.so/file
    
    0 讨论(0)
  • 2020-11-22 07:50

    When you compile your program you must supply the path to the library; in g++ use the -L option:

    g++ myprogram.cc -o myprogram -lmylib -L/path/foo/bar
    
    0 讨论(0)
  • 2020-11-22 07:50

    This error may also be brought about if the symbolic link is to a dynamic library, .so, but for legacy reasons -static appears among the link flags. If so, try removing it.

    0 讨论(0)
  • 2020-11-22 07:51

    Compile Time

    When g++ says cannot find -l<nameOfTheLibrary>, it means that g++ looked for the file lib{nameOfTheLibrary}.so, but it couldn't find it in the shared library search path, which by default points to /usr/lib and /usr/local/lib and somewhere else maybe.

    To resolve this problem, you should either provide the library file (lib{nameOfTheLibrary}.so) in those search paths or use -L command option. -L{path} tells the g++ (actually ld) to find library files in path {path} in addition to default paths.

    Example: Assuming you have a library at /home/taylor/libswift.so, and you want to link your app to this library. In this case you should supply the g++ with the following options:

    g++ main.cpp -o main -L/home/taylor -lswift
    
    • Note 1: -l option gets the library name without lib and .so at its beginning and end.

    • Note 2: In some cases, the library file name is followed by its version, for instance libswift.so.1.2. In these cases, g++ also cannot find the library file. A simple workaround to fix this is creating a symbolic link to libswift.so.1.2 called libswift.so.


    Runtime

    When you link your app to a shared library, it's required that library stays available whenever you run the app. In runtime your app (actually dynamic linker) looks for its libraries in LD_LIBRARY_PATH. It's an environment variable which stores a list of paths.

    Example: In case of our libswift.so example, dynamic linker cannot find libswift.so in LD_LIBRARY_PATH (which points to default search paths). To fix the problem you should append that variable with the path libswift.so is in.

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/taylor
    
    0 讨论(0)
提交回复
热议问题