嵌入式项目的两种编译方法

编译稍复杂的项目,Makefile提供了两种编译方法,分别是原地编译单独输出文件夹编译。平时对于一个工程,我们直接make时,就是把当前文件夹中的.c文件,编译出来的.o文件会放在同一目录下,这种方式叫原地编译,原地编译的好处就是处理起来直观明了,可以直接在源代码目录下看到.o的目标文件。

原地编译有一些坏处:第一,污染了源文件目录。第二的缺陷就是一套源代码只能按照一种配置和编译方法进行处理

,无法同时维护2个或2个以上的配置编译方式。

单独输出文件夹方式的编译,就是在编译时另外指定一个输出目录,将来白所有编译生成的.o文件或生成的其他文件全部丢到那个输出目录下去,源代码目录没做任何的污染,这样在输出目录我们就可看到本次配置编译的所有结果。

具体实例如下:

直接输出文件夹编译有着两种方式:

1)make O=/temp/builld,其中build目录就是我们要把编译过程中产生的.o目标文件和其它文件输出到的目录。

2)export BUILD_DIR=/tmp/build

     make

以上信息来源于Uboot的主Makefile。

#########################################################################
#
# U-boot build supports producing a object files to the separate external
# directory. Two use cases are supported:
#
# 1) Add O= to the make command line
# 'make O=/tmp/build all'
#
# 2) Set environement variable BUILD_DIR to point to the desired location
# 'export BUILD_DIR=/tmp/build'
# 'make'
#
# The second approach can also be used with a MAKEALL script
# 'export BUILD_DIR=/tmp/build'
# './MAKEALL'
#
# Command line 'O=' setting overrides BUILD_DIR environent variable.
#
# When none of the above methods is used the local build is performed and
# the object files are placed in the source directory.
#

猜你喜欢

转载自blog.csdn.net/qslv_bhlt/article/details/79510716
今日推荐