当前位置:网站首页>Difference between GCC -l parameter and -l parameter
Difference between GCC -l parameter and -l parameter
2022-07-24 11:48:00 【Xiaoyuan Xiaoyuan eats dumplings】
-l Parameters are used to specify the library that the program will link to ,-l The parameter is followed by the library name , So what does a library name have to do with a real library file name ? Take the math library , His library name is m, His library file name is libm.so, It's easy to see , Put the header of the library file name lib And tail .so It's the name of the library .
Well, now we know how to get the library name , When we need to use a library name provided by a third party libtest.so, So we just need to libtest.so copy to /usr/lib in , Compile with -ltest Parameters , We can use libtest.so The library ( Of course want to use libtest.so Functions in the library , We also need to work with libtest.so Matching header file ).
Put it in /lib and /usr/lib and /usr/local/lib The library in the library is used directly -l Parameters will link , But if the library files are not in these three directories , It's in other catalogues , At this time, we only use -l Parameter words , Links still go wrong , The error message is probably :“/usr/bin/ld: cannot find -lxxx”, That's the linker ld There 3 I can't find it in one catalog libxxx.so, Here's another parameter -L That comes in handy , For example, common X11 The library of , It's in /usr/X11R6/lib Under the table of contents , We're going to compile with -L/usr/X11R6/lib -lX11 Parameters ,-L The parameter is followed by the name of the directory where the library file is located . Let's take... For example libtest.so Put it in /aaa/bbb/ccc Under the table of contents , The link parameter is -L/aaa/bbb/ccc -ltest
in addition , Most of the libxxxx.so It's just a link , With RH9 For example , such as libm.so It links to /lib/libm.so.x,/lib/libm.so.6 And link to /lib/libm-2.3.2.so,
If there is no such link , There will still be mistakes , because ld I'll just find libxxxx.so, So if you're going to use xxxx library , And only libxxxx.so.x perhaps libxxxx-x.x.x.so, Just make a link ln -s libxxxx-x.x.x.so libxxxx.so
It's always troublesome to write link parameters manually , Fortunately, many library development packages provide programs to generate link parameters , The name is usually xxxx-config, Generally placed on /usr/bin Under the table of contents , such as
gtk1.2 The link parameter generator is gtk-config, perform gtk-config --libs You get the following output "-L/usr/lib -L/usr/X11R6/lib -lgtk -lgdk -rdynamic
-lgmodule -lglib -ldl -lXi -lXext -lX11 -lm", This is how to compile a gtk1.2 What the program needs gtk Link parameters ,xxx-config except –libs In addition to the parameter, another parameter is –cflags Used to generate the directory contained in the header file , That is to say -I Parameters , We will talk about . You can try to execute gtk-config --libs --cflags, Look at the output
The question now is how to use these output results , The stupidest way is to copy, paste or copy , The smart way is to add this... To the compile command linexxxx-config --libs --cflags, For example, compile a gtk Program :gcc gtktest.cgtk-config --libs --cflagsThat's about it . Be careful ` Not single quotes , It is 1 The key on the left of the key .
-include Used to contain header files , But in general, including header files are used in the source code #include xxxxxx Realization ,-include Parameters are rarely used .-I Parameter is used to specify the header file directory ,/usr/include Directories are generally not specified ,gcc Know where to find , But if the header file is not in /usr/include We're going to use -I The parameter specifies , For example, the header file is placed in /myinclude Directory , Then compile the command line to add -I/myinclude Parameters , If you don't, you'll get a "xxxx.h: No such file or directory" Error of .-I Parameters can be relative paths , For example, the header file is in the current directory , It can be used -I. To specify the .
边栏推荐
- 一周精彩内容分享(第13期)
- 离散分布常用公式及应用场景
- The art of management - driving software R & D efficiency through leadership
- DevOps及DevOps常用的工具介绍
- SSH跨平台终端工具tabby推荐
- MOS tube - Notes on rapid recovery application (I) [principle]
- 字符串——541. 反转字符串 II
- Types and history of bugs in it circle
- 安装jmeter
- [QNX hypervisor 2.2 user manual]9.2 CmdLine
猜你喜欢

Semaphore details

容错、熔断的使用与扩展

三、MFC消息映射机制实现原理
![Operational amplifier - Notes on rapid recovery [II] (application)](/img/fd/e12f43e23e6ec76c2b44ce7813e204.png)
Operational amplifier - Notes on rapid recovery [II] (application)

In kuborad graphical interface, operate kubernetes cluster to realize master-slave replication in MySQL

[TA frost wolf umay - "hundred people plan] Figure 3.3 surface subdivision and geometric shader large-scale grass rendering

The third day of hcip mGRE experiment

Install JMeter

GCC的基本用法

NFT digital collection system construction - app development
随机推荐
Shell Scripting tips
Tensor and numpy convert "suggested collection" to each other
视频回放 | 如何成为一名优秀的地学和生态学领域的国际期刊审稿人?
The difference between where and having
Code of login page
Detailed OSPF configuration of layer 3 switch / router [Huawei ENSP experiment]
6k+ star,面向小白的深度学习代码库!一行代码实现所有Attention机制!
[TA frost wolf umay - "hundred people plan] Figure 3.3 surface subdivision and geometric shader large-scale grass rendering
哈希——242.有效的字母异位词
NFT digital collection system construction - app development
4*4图片权重的收敛规则
字符串——541. 反转字符串 II
L1-043 reading room
HCIP MGRE实验 第三天
Hash - 349. Intersection of two arrays
Optimization method of "great mathematics for use" -- optimal design of Cascade Reservoir Irrigation
What is the difference between strong reference, soft reference, weak reference and virtual reference?
哈希——18. 四数之和
Win10 icon turns white, recovery method
哈希——15. 三数之和