Skip to main content
  1. Posts/

Commonly-used Building Options Explained

··424 words·2 mins·
Linux GCC C C++
Table of Contents

On Linux system, if we do not have root priviledge, we can not use package managers to install a package to its default location (usually under /usr). Besides, the packages installed by the package managers are often too old to have the latest features. Or, even if we have root priviledge, we do not want to mess up with the system-wide packages and just want to experiment with a package locally. On these ocassions, we may want to install the package to a custom location.

The standard procedure to build and install a package from source is something like the following:

./configure
make && make install

By default, the package will be installed under /usr and you must have root priviledge. If you are not familiar with these steps. Read here and here for more discussions on what each step does.

In order to install the package to a custom location and find dependency packages which are not installed on standard locations, we need to set custom options and variables for the configure script. In this post, I will explain the meaning of --prefix, CLFAGS, CXXFLAGS, CPPFLAGS and LDFLAGS.

The meaning of these options and variables
#

--prefix
#

--prefix is used to tell make where to install the compiled packages. For example, if you use --prefix=$HOME/local, after building the package using make -j, if you do a make install, the binary file will be put in $HOME/local/bin, the library file will be put in $HOME/local/lib or $HOME/local/lib64, the header file will be put in $HOME/local/include and the help file and other resources may be put in $HOME/local/share.

CFLAGS and CXXFLAGS
#

CFLAGS and CXXFLAGS are used to set up C and C++ compilers respectively. On most Linux system, the C compiler is usually gcc, while the C++ compilers is usually g++.

CPPFLAGS
#

The CPPFLAGS is often mis-understood to set up C++ compiler options. In fact, it is used by C/C++ preprocessors. It tells preprocessor where to find the header files. If you need to set up C++ compiler, you should use CXXFLAGS variable. A valid CPPFLAGS is something like CPPFLAGS="-I$HOME/local/include".

LDFLAGS
#

LDFLAGS is used to set up the path of library files. For example, LDFLAGS="-L$HOME/local/lib".

Conclusion
#

In this post, I introduced some of the most commonly-used options and flags for the configure script when building packages from source. Understanding these options and flags will help you succeed in building the packages.

Reference
#

Related

How to Compile and Install Latest Version of GCC on CentOS 7
··289 words·2 mins
Linux C++ CentOS GCC
Install LLVM/Clangd from Source on CentOS 7
··445 words·3 mins
Linux Clang C++
Building OpenCV from Source on Linux
·449 words·3 mins
Linux C++ OpenCV