[原创]交叉编译时,如何链接指定路径下的库文件

来源:互联网 发布:苹果手机虚拟专用网络 编辑:程序博客网 时间:2024/05/18 03:15

Autoconf book(4) AM_CONDITIONAL

AM_CONDITIONAL(name, testcode)

ARG1: the name of a conditional ,
ARG2: a shell statement that is used to determine whether the conditional should be true or false.

If the shell code returns a successful status, then the conditional will be true. Any conditional in your `configure.in' is automatically available for use in any `Makefile.am' in that project.
 
上文来自链接:

http://ps-buaa.spaces.live.com/blog/cns!ACFF11BFA33D6971!180.entry

 

本人移植mount,在powerpc交叉编译时,用到的blkid库,需要到/home/user-name/ltib/rootfs/lib路径下查找。为了不改动源代码,这个问题如何解决呢?我找到了方法如下:

 

在整个工程的configure.in文件中加入如下代码,即在所有Makefile中引入条件变量MY_CROSS_COMPILE:

#configure.in

if test x$CC = xgcc; then
  AC_MSG_WARN($BLKID --------------------------------------) #message only for test
  AM_CONDITIONAL(MY_CROSS_COMPILE,false)
else
  AC_MSG_WARN($BLKID +++++++++++++++++++++) #message only for test
  AM_CONDITIONAL(MY_CROSS_COMPILE,true)
fi

 

在需要blkid库的Makefile.am文件中

if MY_CROSS_COMPILE    #(目标机交叉编译)
AM_CPPFLAGS = -include $(top_builddir)/config.h -I ../include /
 -DLOCALEDIR=/"$(localedir)/" -I /home/user-name/ltib/rootfs/usr/include
AM_CFLAGS = -fsigned-char  -I /home/user-name/ltib/rootfs/usr/include
else   #(PC机编译)

AM_CPPFLAGS = -include $(top_builddir)/config.h -I ../include /
 -DLOCALEDIR=/"$(localedir)/"
AM_CFLAGS = -fsigned-char 
endif

 

lib_mount_la_LIBADD = $(LDADD_common)

LDADD_common = 

 

if MY_CROSS_COMPILE   #(目标机交叉编译)
 LDADD_common += -L$(LTIB_PATH)/rootfs/usr/lib -lblkid -luuid
else    #(PC机编译)
 LDADD_common += -lblkid -luuid
endif