Cflags/cppflags/cxxflags in Makefile Introduction

Source: Internet
Author: User

Let's take a look at a list of common predefined variables in makefile.

CFLAGS represents an option for the C compiler, cxxflags represents an option for the C + + compiler. These two variables actually cover the two steps of compiling and assembling. Most programs and libraries at compile time the default optimization level is "2" (using the "-o2" option) and with debug symbols to compile, that is, cflags= "-o2-g", cxxflags= $CFLAGS. In fact, "-O2" has enabled the vast majority of security optimization options. On the other hand, since most options can be used for both variables at the same time, only the option to use one of these variables is described at the end. [Reminder] The options listed below are non-default options, you just need to add them as needed.

CFLAGS: Specifies the path to the header file (. h file), such as: Cflags=-i/usr/include-i/path/include. Similarly, when a package is installed, an include directory is created under the installation path, and when a problem occurs during the installation, try adding the Include directory of the previously installed package to the variable.

ldflags: Some of the optimization parameters used by the compiler, such as GCC, or the location of the library files can be specified. Usage: ldflags=-l/usr/lib-l/path/to/your/lib. Each installation of a package will almost certainly create a Lib directory in the installation directory. If you install a package clearly, and install another package, it Leng said to find, you can express the Lib path of the package to join the Ldfalgs to try.

LIBS: Tell the linker which library files to link to, such as LIBS =-lpthread-liconv

Simply put, Ldflags is telling the linker where to look for library files, and Libs is telling the linker which library files to link to. However, when using the link stage these two parameters will be added, so you can even swap these two values, there is no problem.

Sometimes ldflags specifies-l Although the linker can find the library to link, but the runtime linker could not find the library, if you want to let the Software runtime library file path also extended, then we need to add the two libraries to "-wl,r":

Ldflags =-l/var/xxx/lib-l/opt/mysql/lib-wl,r/var/xxx/lib-wl,r/opt/mysql/lib

If you set the environment variable before you execute./configure export ldflags= "-l/var/xxx/lib-l/opt/mysql/lib-wl,r/var/xxx/lib-wl,r/opt/mysql/lib", Note Set environment variables there can be no spaces on either side of the equals sign, and enclose the quotation marks (shell usage). Then after the execution of configure, Makefile will set this option, the link will have this parameter, compiled executable program library file search path is extended.

Part of the Content Reference document: http://blog.csdn.net/lidan3959/article/details/8677515

Cflags/cppflags/cxxflags in Makefile Introduction

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.