compiler optimization, about Cflags and cxxflags
This article from Jin Bu "gcc compilation Optimization Guide" http://lamp.linux.gov.cn/Linux/optimize_guide.html excerpt can be personally understandable and recommend the use of the part, stay for reference.
One, Cflags and Cxxflags
Cflags represents the option for the C compiler, cxxflags represents the options f
Many times, some special libraries are used to compile and executeProgramYou need to add additional cflags and libs. Otherwise, the system will prompt that the specified header file or "undefined reference to..." error message cannot be found.
If the libxml API is used in test. C
$ Gcc-wall-O test. c
An error message is displayed.Run
$ Ls/usr/lib/pkgconfig/| grep libxmllibxml-2.0.pc
$ CAT/usr/lib/pkgconfig/libxml-2.0.pc prefix =/users =/usrlibdir
Makefile options CFLAGS, LDFLAGS, LIBS, cflagsldflagsMakefile options CFLAGS, LDFLAGS, LIBS
CFLAGS indicates the options used in the C compiler,CXXFLAGS indicates the options used for the C ++ compiler.These two variables actually cover the compilation and compilation steps.
CFLAGS: Specifies the path of the header fil
Many times, with special libraries, you need to add additional cflags and LIBS when compiling executable programs. Otherwise, you will be prompted not to find the specified header file or "Undefined reference to ..." The error message.
If the Libxml API is used in the program test.c, direct
Copy Code code as follows:
$ Gcc-wall-o Test test.c
An error message is prompted.
Perform
Copy Code code as follows:
$ ls/us
Many times, when using some special libraries to compile executable programs, you need to add additional CFLAGS and LIBS. otherwise, the system will prompt that the specified header file cannot be found or "undefined reference... "error message.
If the libxml api is used in test. c
Copy codeThe Code is as follows: $ gcc-Wall-o test. c
An error message is displayed.RunCopy codeThe Code is as follows: $ ls/usr/lib/pkgconfig/| grep libxmlLibxml-2.0.pc
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 represents an option for the C compiler.Cxxflags represents options for the C + + compiler.These two variables actually cover the two steps of compiling and assembling.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 dur
CFLAGS represents options for the C compilerCxxflags represents options for the C + + compilerThese two variables actually cover the two steps of compiling and assemblingCFLAGS: Specifies the path to the header file (. h), 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 in
specified for GCC in different hardware environments for optimal performance. This article is separated from a programming instruction manual named Gentoo Linux, which is helpful for compiling programs.
--------------------------------------------------------------------------------
I. version 1.2 (gcc 2.9.x)
I386 (Intel), do you really want to install gentoo on that? CHOST = "i386-pc-linux-gnu" CFLAGS = "-march = i386-O3-pipe-fomit-frame-pointer" C
Article title: gcc best compilation parameters. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
I. Version 1.2 (gcc 2.9.x)
I386 (Intel), do you really want to install gentoo on that?
CHOST = "i386-pc-linux-gnu"
CFLAGS = "-march = i386-O3-pipe-fomit-frame-pointer"
CXXFLAGS = "-march = i386-O3-pipe-fomit-frame-poi
: make-f makefile. bcc-DSTATIC
# Write by: Mao yongjun (mao_yj@msn.com)
# Makefile for building Lua# See ../INSTALL for installation instructions# See ../Makefile and luaconf. h for further customization
#== Change the settings below to suit your environment =========================
CC = bcc32CFLAGS =-DNDEBUG-DNO_STRICT; _ NO_VCL-Hc-w-par-O2-B-k--vi-tWM-c-P-CFLAGSEXE =-D_isatty = isatty $ (CFLAGS)CLINK = ilink32CLFLAGS =-Gn-j-xDLLOBJS = c0d32. objEXE
GCC compilation optimization settings-general Linux technology-Linux programming and kernel information. The following is a detailed description. Check your gcc version:
# Gcc -- version
* Obtain the cpu model:
# Cat/proc/cpuinfo
* Create the make. conf file under/etc/and write different content according to the cpu model (note that your gcc version must be above 3.0 ):
I386 (Intel)
CHOST = "i386-pc-linux-gnu"
CFLAGS = "-march = i386-O3-pipe-fom
How can we optimize your system? The following is a simple and small method, but the optimization and adjustment of a system is far more than that. The performance needs to be adjusted according to actual needs. There is no way to meet all system requirements.
1. Check your gcc version:Note that your gcc version must be later than 3.0.
# Gcc -- version
2. obtain your cpu model:
Cat/proc/cpuinfo
3. Create the make. conf file under/etc/and write different contents according to the cpu model.
◆ I
efficiency of the software, and the second is to accelerate the download of the software for ports.After the system is installed, the make. conf file does not exist by default. You can create one by yourself. (Self-reliance, good clothes and food, ha !)First, adjust the GCC compilation parameters.# Touch/etc/make. conf# Ee/etc/make. confJoin:CFLAGS =-march = pentium-m-O2-pipe-msse2-mmmx-mfpmath = sseCXXFLAGS =$ {CFLAGS}Among them,-march refers to the
into a compilation file rule. $ @ is the target object.%. S: %. c$ (CC) $ (cflags) $ (extra_cflags) $ (cflags _ $ @)-S $ # Create a pre-processing file rule for file C.%. I: %. c$ (CPP) $ (cflags) $ (extra_cflags) $ (cflags _ $ @) $ # Compile the c file into the target file rule, $ #Generate the flags file in the dire
libxxxx-x.x.x.so libxxxx. So
It is always troublesome to manually write the link parameters. Fortunately, many libraries provide programs that generate the link parameters.Usually XXXX-config, which is stored in the/usr/bin directory, for example
The Program for generating the Link parameter of gtk1.2 is GTK-config. Run GTK-config -- libs to get the following output "-L/usr/lib-L/usr/x11r6/lib-lgtk-lgdk-rdynamic
-Lgmodule-lglib-LDL-LXI-lxext-lx11-lm ", which is the G required to compile a gtk1.
they are expanded.
The first class is called the recursive expansion Variable (Recursively Expanded Variable ). Use the = or define keywordsThis variable can be defined. If the definition of the variable references other variables, the reference will continue to expand,Until the latest definition of the referenced variable is found and returned as the value of the change volume. For example:[Code: 1] foo = $ (bar)Bar = $ (ugh)Ugh = Huh? [/Code: 1]What is the value of $ (foo? $ (Foo) is expanded
= GCC # Where are include file keptinclude = . # Options For Developmentcflags =-G-wall-ANSI # options For Release # cflags =-O-wall- Ansimyapp: Main. o 2 . O 3 . O $ (cc) -O MyApp main. o 2 . O 3 . Omain. O: Main. c a. h $ (cc) -I $ (include) $ (cflags )- C main. c 2 . O: 2 . C a. h B. H $ (cc) -I $ (include) $ (cflags)-C 2 . C 3 . O: 3 . C B. H C. H
Download Word: Click to open the link
I. Only one. c file is written in makefile.
Main. c
#include
Makefile
CFLAGS=-WallCC=gccmain:main.o$(CC) $(CFLAGS) main.o -o mainmain.o:main.c$(CC) $(CFLAGS) -c main.c -o main.oclean:$(RM) main.o$(RM) main.PHONY:clean
The second method of makefile:
CFLAGS=-WallCC=gccmain:m
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.