gcc/Cross-compiling

Source: Internet
Author: User

1.linux GCC contains the C + + compiler, GCC and CC are the same, C + + and g++ are the same, the general C program is compiled with GCC, C + + program is compiled with g++.


2.linux GCC application: Direct compile generates a.out file-o Specifies the name of the generated file.


3.linux gcc compile encountered "undefined reference to ' xxxxx '" error, not compile error, connection error, no libraries are specified for the linked program. such as the mathematical function library to

plus-LM, database library to add-lsqlite3, thread function library to add-lpthread and so on.
parse: the-l parameter is used to specify the library to which the program is linked, and the-l parameter is followed by the library name, such as the math library, whose library name is M, His library file name is libm.so, it is easy to see that the library file name of the head lib and tail so removed is the name of the library.
record, when we only use the-l parameter, the link will still go wrong,

the error message is probably: "/usr/bin/ld:cannot find-lxxx", which is the link program LD in those 3 directories can not find libxxx.so, then another parameter-L will come in handy, such as commonly used X11 library, it in/usr/x11r6/lib mesh recording, we compile with the-l/usr/x11r6/lib-lx11 parameter, the-l parameter followed by the directory name where the library file is located. For example, we put libtest.so in the/AAA/BBB/CCC directory, the link parameter is-l/aaa/bbb/ccc-ltest


4.linux GCC compilation encountered "Xxxx.h:no such file or directory" error
The-i parameter is used to specify the header file directory, the/usr/include directory is generally not specified, GCC knows where to find, but if the header file is not in/usr/include we will use the-i parameter specified, such as the header file in the/myinclude directory, The compiler command line will add the-i/myinclude parameter.


5.linux GCC Program Optimization parameters
In general,-o2 is used to optimize program use, such as GCC test.c-o2, the optimization of the program is smaller than not optimized, the execution speed may also improve.


cross-compilation tools and Usage methods under 6.linux (used in platform porting and embedded development)
Our usual compilation is called local compilation, that is, in the current platform compiled, compiled programs are also executed locally, on the local machine to compile the program to its
the compiler on his machine is called a cross compiler,
This is similar to the local GCC, but one thing is special: the-L and-I parameters must be used to specify the library and header files for the third-party system
( X86) library (header files can sometimes be used locally)
Example: SPARC-XXXX-LINUX-GNU-GCC test.c-l/path/to/sparclib-i/path/to/sparcinclude
The most important software development tool in Linux is GCC. GCC is the GNU C and C + + compiler. In fact, GCC is capable of compiling three languages: C, C + +
and Object C (a type-oriented extension of the C language). Use the GCC command to compile and connect C and C + + source programs at the same time.
GCC can be used to compile both C and C + + programs. In general, the C compiler uses the suffix name of the source file to determine whether it is a C program or C + +
program. In Linux, the C source file has the suffix name. C, and the C + + source file has a suffix named. C or. cpp.
the GCC command compiles only C + + source files and cannot be automatically connected to libraries used by C + + programs. Therefore, the g++ command is typically used to complete C + +
The program compiles and connects, and the program automatically calls GCC to implement the compilation.
-ansi only supports the ANSI standard C syntax. This option will prohibit certain features of GNU C, such as ASM or typeof keywords.
-C compiles and generates only the target file.
-DMACRO defines macro macros with the string "1".
-DMACRO=DEFN defines macro macros with the string "DEFN".
-E only runs the C precompiled compiler.
-G generates debug information. The GNU debugger can take advantage of this information.
-idirectory Specifies additional header file search paths for directory.
-ldirectory Specifies additional library search paths for directory.
-llibrary searches for the specified library of libraries when connected.
-m486 code optimization for 486.
-o file to generate the specified output files. Used when generating an executable file.
-o0 not optimized for processing
-O or-o1 optimization generates code.
-o2 further optimization.
-o3 is further optimized than-O2, including the inline function.
-shared generate a shared destination file. Typically used when building a shared library.
-static prohibit the use of shared connections.
-umacro to remove macro macro definitions
-W does not generate any warning messages.
-wall generates all warning messages.

The meaning of 7.build,host,target
"Build" is the computer you are currently using.

"Host" Your goal is to compile a program that can run on host.

The "target" normal program does not have this concept. For those who want to compile the compiler, this property determines where the program compiled by the new compiler can run!
Such as:
I want to write a program on the Fl2440arm Development Board, but because debugging trouble on the board, I do not want to build on the arm Development Board, so I want to on my own computer
Develop and then copy the past to it with. Then I need a build on my x86 to build a "gcc that can run on my x86 (host), this new GCC
The program is programmed to run on arm (target). This option is Build=x86,host=x86,target = arm.
This time I use this gcc to compile a HelloWorld, this HelloWorld build=x86,host=arm

gcc/Cross-compiling

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.