Detailed explanation of the functions of -I (uppercase i), -L (uppercase l), and -l (lowercase l) when compiling programs with g++ under Linux

Detailed explanation of the functions of -I (uppercase i), -L (uppercase l), and -l (lowercase l) when compiling programs with g++ under Linux

As an entry-level Linux user, I have used simple gcc/g++ operations many times, but sometimes libraries are used for slightly more complex programs. When I encountered a problem, I looked up a lot of information summarized by my predecessors, and left a script hoping it would be helpful to my friends. I'd be very happy if I could solve your problem too, hehe.
For example: libz.so

g++ -o compress compress.cpp -I/home/include/ -L/lib/ -lz

(1) -I (uppercase i)

The compiler searches for header files in the path specified by -I.

-I/home/include/ means that -I/home/include/ directory is used as the first directory to search for header files. The search order is:

/home/include/ -->/usr/include -->/usr/local/include

(2) -L (uppercase l)

It means: the compiler searches for the library file in the path specified by -L. Generally, you can use -l to specify multiple library files at once after -L.

-L/lib/ means to search for library files in the /lib/ directory

(3) -l (lowercase l)

It means: the compiler searches the system default path. If it cannot find the library, it searches the current directory. If it cannot find the library in the current directory, it searches the path set to the top of the environment variables such as LD_LIBRARY_PATH . If it still cannot find the library, the compiler prompts that it cannot find the library.

This example uses the gunzip library, the library file name is libz.so, and the library name is z. It is easy to see that removing the first lib and the last .so of the library file name gives you the library name.

Summarize

This is the end of this article about the detailed explanation of the functions of -I (uppercase i), -L (uppercase l) and -l (lowercase l) when compiling g++ programs under Linux. For more relevant content about Linux g++ compiler programs, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to use g++ to compile cpp project under linux
  • Summary of using g++ to compile C++ in Linux environment
  • Methods of compiling and using static and dynamic libraries with g++ under Linux
  • How to compile GDAL dynamic library with g++ in Linux environment
  • Detailed explanation of the basic use of Linux C++ compiler g++

<<:  Calling Baidu Map to obtain longitude and latitude in Vue

>>:  Optimization of data tables in MySQL database, analysis of foreign keys and usage of three paradigms

Recommend

The most complete 50 Mysql database query exercises

This database query statement is one of 50 databa...

Binary installation of mysql 5.7.23 under CentOS7

The installation information on the Internet is u...

Vue implements local storage add, delete and modify functions

This article example shares the specific code of ...

Will the deprecated Docker be replaced by Podman?

The Kubernetes team recently announced that it wi...

Detailed tutorial on installing Python 3.6.6 from scratch on CentOS 7.5

ps: The environment is as the title Install possi...

Steps to change mysql character set to UTF8 under Linux system

Table of contents 1. Check the MySQL status in th...

Native JS to achieve blinds special effects

This article shares a blinds special effect imple...

Detailed tutorial for installing mysql5.7.21 under Windows

This article shares the installation tutorial of ...

Deployment and configuration of Apache service under Linux

Table of contents 1 The role of Apache 2 Apache I...

Discussion on default margin and padding values ​​of common elements

Today we discussed the issue of what the margin v...

MySQL uses covering index to avoid table return and optimize query

Preface Before talking about covering index, we m...