The solution to the lack of a connection library when Linux compiles programs __linux

Source: Internet
Author: User
Solution to the lack of a connection library when Linux compiles programs

When Linux compiles a program, it prompts the following error if the connection library is missing:
$ gcc Test.c-o test-lxxx
/usr/bin/ld:cannot find-lxxx
Collect2:error:ld returned 1 exit status

The-L and-l parameters of the GCC command are introduced first.
The-l parameter is used to specify the library to which the program will link, and the-l parameter is followed by the library name, so what does the library name have to do with the real library file name?
Take the math library, his library name is M, his library filename is libm.so, it is easy to see, the library file name of the head Lib and tail. So remove is the name of the library.

OK, now we know how to get the name of the library, for example, we have to use a third party to provide the library name is libtest.so, then we just copy the libtest.so into the/usr/lib, compile with the-ltest parameters, We will be able to use the Libtest.so library (of course to use the Libtest.so library functions, we also need to match with the libtest.so header file).

The libraries placed in/lib and/usr/lib and/usr/local/lib can be linked directly with the-l parameter, but if the library files are not placed in these three directories, but in other directories, then we only use the-l parameter, the link will still be wrong, the error message is probably: "/usr/bin /ld:cannot find-lxxx ", that is, link program LD cannot find libxxx.so in those three directories. At this time another parameter-L came in handy, such as the commonly used X11 library, it placed in the/usr/x11r6/lib directory, we compile with the-l/usr/x11r6/lib-lx11 parameter, the-l parameter followed by the library file is the directory name. For example, we put libtest.so in the/AAA/BBB/CCC directory, the link parameter is-l/aaa/bbb/ccc-ltest.

Now take the Ubuntu system for example and talk about solutions.
Find the path to the static library XXX first:
$ sudo find/-name *xxx*
Suppose it is/usr/local/lib/xxx to locate the XXX library file path.
The directory is then compiled with the-l option:
$ gcc Test.c-o test-l/usr/local/lib/xxx-lxxx


Solve the problem.


Reference:

http://blog.csdn.net/jiafu1115/article/details/8842240

http://blog.csdn.net/wangzhen209/article/details/47153239

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.