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

A detailed introduction to the basics of Linux scripting

Table of contents 1. Script vim environment 2. Ho...

Detailed discussion of MySQL stored procedures and stored functions

1 Stored Procedure 1.1 What is a stored procedure...

HTML Basics - Simple Example of Setting Hyperlink Style

*** Example of setting the style of a hyperlink a...

Summary of shell's method for determining whether a variable is empty

How to determine whether a variable is empty in s...

How to install Linux flash

How to install flash in Linux 1. Visit the flash ...

How to install OpenSuse on virtualbox

The virtual machine is installed on the host mach...

Implementation of multiple instances of tomcat on a single machine

1. Introduction First of all, we need to answer a...

Example analysis of the principle and solution of MySQL sliding order problem

This article uses examples to explain the princip...

Linux debugging tools that developers and operators must look at [Recommended]

System performance expert Brendan D. Gregg update...

How to create Apache image using Dockerfile

Table of contents 1. Docker Image 2. Create an in...

CSS method of controlling element height from bottom to top and from top to bottom

Let’s start the discussion from a common question...

Teach you how to build the vue3.0 project architecture step by step

Table of contents Preface: 1. Create a project wi...