Arm-Linux-GCC installation and environment variable settings

Source: Internet
Author: User

1. Download arm-linux-gcc-3.4.1.tar.bz2 to any directory and download it to my personal folder/home/WRQ
The arm-linux-gcc-3.4.1.tar.bz2 is as follows: http://www.handhelds.org/download/projects/toolchain/arm-linux-gcc-3.4.1.tar.bz2

2. Extract arm-linux-gcc-3.4.1.tar.bz2
# Tar-jxvf arm-linux-gcc-3.4.1.tar.bz2
The decompression process takes some time. The decompressed file forms a usr/local/folder. Enter this folder and copy the arm folder to/usr/local /.
# Cd usr/local/
# Cp-rv arm/usr/local/
Currently, the cross-compiled assembly is under/usr/local/ARM/3.4.1/bin.

3. Modify environment variables and add the path of the cross compiler to path. (There are three methods. We strongly recommend that you use method 1)
Method 1: Modify the/etc/bash. bashrc file.
# Vim/etc/bash. bashrc
Add:
Export Path = $ path:/usr/local/ARM/3.4.1/bin
Export path
Method 2: Modify the/etc/profile file:
# Vim/etc/profile
Add path settings and add the following at the end to save the/etc/profile file:
Export Path = $ path:/usr/local/ARM/3.4.1/bin
Method 3: # export Path = $ path:/usr/local/ARM/3.4.1/bin
Note: (this is only valid under the current terminal !)

4. Make the new environment variable effective immediately without restarting the computer:
Method 1: # source/root/. bashrc
Method 2: # source/etc/profile

5. Check whether the path is added to the path:
# Echo $ path
/Usr/local/ARM/bin is displayed, indicating that the path of the cross compiler has been added to path. So far, the cross-compilation environment installation is complete.
6. test whether the installation is successful.
# Arm-Linux-gcc-V
The above command will display the arm-Linux-GCC information and version, which is my display information:
Reading specs from/usr/local/ARM/3.4.1/lib/GCC/ARM-Linux/3.4.1/specs
Configured with:/work/crosstool-0.27/build/ARM-Linux/gcc-3.4.1-glibc-2.3.2/GCC-3.4.1/configure -- target = arm-Linux -- Host = i686-host_pc-linux-gnu

-- Prefix =/usr/local/ARM/3.4.1 -- With-headers =/usr/local/ARM/3.4.1/ARM

-Linux/include -- With-local-Prefix =/usr/local/ARM/3.4.1/ARM-Linux -- disable

-NLS -- enable-threads = POSIX -- enable-symvers = GNU -- enable-_ cxa_atexit -- enable-packages ages = C, c ++ -- enable-shared -- enable-c99 -- enable-Long-long
Thread model: POSIX
GCC version 3.4.1

7. Compile the hello World Program and test the cross tool chain.
Write down the following Hello World Program and save it as hello. C.
# Include <stdio. h>
Int main ()
{
Printf ("Hello world! /N ");
Return 0;
}

Run the following command:
# Arm-Linux-gcc-O hello. c
-------------------------------------------------------------

Modify environment variables in this step to modify the/etc/profile file
Add the arm-Linux-GCC path to path

If ["'id-U'"-EQ 0]; then
Path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin: /usr/local/ARM/3.4.1/bin"
Else
Path = "/usr/local/bin:/usr/Games"
Fi
Then, source/etc/profile can refresh the environment variables.
If you try other methods, it does not seem to work ........

When using Linux for development, we need to configure software-related information when installing a software. In addition, we need to configure the environment variables. For example, you need to configure the $ PATH variable when installing arm-Linux-GCC. The following describes the directories to read when Linux Shell is working. We all know that in Linux, shell is used to interact with the system (I .e., some commands ). Some of these commands are shell-based internal commands, and some are Linux programs. Since these commands need to be stored. How to tell shell the location of these commands should be set through environment variables. If you do not set environment variables, you must go to that directory to execute commands related to the software. Is this too troublesome. The shell will automatically search for directories during use. Why did you find it on your own. Haha

Normally, files related to environment variables are ):

/Etc/profile and/etc/bashrc and. bashrc under the current user's home directory

The following sections describe:

/Etc/profile mainly configures some system variables. The/etc/bashrc is for all users who use the bash shell.

The. bashrc in the home directory is for a single system user. For example, the. bashrc in the root directory takes effect only for the root user.

You can use env set and other commands to display the environment variables of your current shell.

You can also use export to temporarily add environment variables. The following describes how to use export:

Export [-FNP] [variable name] = [variable setting value]

Note: When executing a program in shell, shell provides a set of environment variables. Export allows you to add, modify, or delete environment variables for subsequent programs. The effect of export is only true for this login operation.

Parameters:
-F indicates the function name in [variable name.
-N: Delete the specified variable. The variable is not actually deleted, but is not output to the execution environment of subsequent commands.
-P: list all environment variables that the shell assigns to the program.

However, we will focus on modifying files, because this will solve this problem at one time.

If you want all users' shells to use this path, you need to modify the/etc/bashrc file and how to modify it. The specific situation is analyzed. The following is a description written when I installed arm-Linux-GCC:

If [-D/usr/local/ARM/2.95.3]; then
Path =/usr/local/ARM/2.95.3/bin: "$ {path }"
Fi

PATH is followed by the bin directory of the software you installed.

If you want a single user to use this environment variable, modify the. bashrc

After modification, log on again to make the change take effect.

Knowledge about shell reading configuration during logon:

For Shell login:

Log on to Shell

Read order:
Read/etc/profile first
. Bash_profile under the Home Directory
Bashrc under the Home Directory
Finally read/etc/. bashrc
Finally, read all the script files in the/etc/profile. d file.
Specific functions of each file:

(1)/etc/profile: This file sets the environment information for each user in the system. When the user logs on for the first time, this file is executed. and from/etc/profile. d. Collect shell settings in the configuration file of the directory (that is, automatically execute/etc/profile at login. d directory ).
(2)/etc/bashrc: execute this file for every user running bash shell. When bash shell is opened, the file is read.
(3 )~ /. Bash_profile: each user can use this file to input the shell information dedicated to their own use. When a user logs on, this file is only executed once! By default, it sets some environment variables to execute the user's. bashrc file.
(4 )~ /. Bashrc: This file contains bash information dedicated to your bash shell. This file is read when you log on and every time you open a new shell.
(5)
~ /. Bash_logout: execute this file every time you exit the system (exit bash shell.
In addition, the variables (global) set in/etc/profile can act on any user ~ /. The variables (local) set in bashrc and so on can only inherit
The variables in/etc/profile are "Parent-Child" relationships. (The configuration in the/etc/directory is only global and can be used by any user)
(6 )~ /. Bash_profile is interactive and login to run bash ~ /. Bashrc is the interactive non-login mode that enters Bash. Generally, the two settings are roughly the same, so the former usually calls the latter.

Okay. Let's talk about it first!
The above content comes from the network.

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.