Autotools 编译工程

Autotools-Based Projects

Once you have a suitable cross-toolchain installed, it is very easy to develop a project outside of the OpenEmbedded build system. This section presents a simple "Helloworld" example that shows how to set up, compile, and run the project.

5.1.1. Creating and Running a Project Based on GNU Autotools

Follow these steps to create a simple Autotools-based project:

  1. Create your directory: Create a clean directory for your project and then make that directory your working location:

         $ mkdir $HOME/helloworld
         $ cd $HOME/helloworld
                        
  2. Populate the directory: Create hello.cMakefile.am, and configure.in files as follows:

    • For hello.c, include these lines:

           #include <stdio.h>
      
           main()
              {
                 printf("Hello World!\n");
              }
                                  
    • For Makefile.am, include these lines:

           bin_PROGRAMS = hello
           hello_SOURCES = hello.c
                                  
    • For configure.in, include these lines:

           AC_INIT(hello.c)
           AM_INIT_AUTOMAKE(hello,0.1)
           AC_PROG_CC
           AC_PROG_INSTALL
           AC_OUTPUT(Makefile)
                                  
  3. Source the cross-toolchain environment setup file: Installation of the cross-toolchain creates a cross-toolchain environment setup script in the directory that the ADT was installed. Before you can use the tools to develop your project, you must source this setup script. The script begins with the string "environment-setup" and contains the machine architecture, which is followed by the string "poky-linux". Here is an example that sources a script from the default ADT installation directory that uses the 32-bit Intel x86 Architecture and the jethro Yocto Project release:

         $ source /opt/poky/2.0/environment-setup-i586-poky-linux
                        
  4. Generate the local aclocal.m4 files and create the configure script: The following GNU Autotools generate the localaclocal.m4 files and create the configure script:

         $ aclocal
         $ autoconf
                        
  5. Generate files needed by GNU coding standards: GNU coding standards require certain files in order for the project to be compliant. This command creates those files:

         $ touch NEWS README AUTHORS ChangeLog
                        
  6. Generate the configure file: This command generates the configure:

         $ automake -a
                        
  7. Cross-compile the project: This command compiles the project using the cross-compiler. The CONFIGURE_FLAGS environment variable provides the minimal arguments for GNU configure:

         $ ./configure ${CONFIGURE_FLAGS}
                        
  8. Make and install the project: These two commands generate and install the project into the destination directory:

         $ make
         $ make install DESTDIR=./tmp
                        
  9. Verify the installation: This command is a simple way to verify the installation of your project. Running the command prints the architecture on which the binary file can run. This architecture should be the same architecture that the installed cross-toolchain supports.

         $ file ./tmp/usr/local/bin/hello
                        
  10. Execute your project: To execute the project in the shell, simply enter the name. You could also copy the binary to the actual target hardware and run the project there as well:

         $ ./hello
                        

    As expected, the project displays the "Hello World!" message.

ref:http://www.yoctoproject.org/docs/2.0/ref-manual/ref-manual.html#usingpoky-components-bitbake

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值