交叉编译lib
1. 交叉编译libnpg库 ./configure CC=mipsisa32-elf-gcc --host=mipsisa32-linux 求大神给予帮助
编译安装。关键要看configure后,屏幕上出现的那一堆内容的最末尾有没有error:
没有就可以进行下一步。至于其他的,例如warning,可以忽略。
make和make install也是一样
2. gcc交叉编译怎么找头文件及lib库的
是在specs里面读取的路径信息。
命令行中键入 gcc -v
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with: /usr/build/package/orig/test.respin/gcc-3.4.4-3/configure --ver
bose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libe
xecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-langu
ages=c,ada,c++,d,f77,pascal,java,objc --enable-nls --without-included-gettext --
enable-version-specific-runtime-libs --without-x --enable-libgcj --disable-java-
awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --enable-thre
ads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptio
ns --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: posix
gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
注意“--prefix=/usr” 以及“--libdir=/usr/lib ”
表示gcc ld as 等可执行文件安装在/usr/bin,而libc.a 等文件是在/usr/lib中。
解压缩交叉编译器时,也是要解压缩在在--prefix 指定的目录下。
比如 下载了arm-linux 的交叉编译器cross-3.3.2.tar.bz2,解压缩之后,运行 arm-linux-gcc -v
得到 --prefix=/usr/local/arm。那么就要把 bin lib 等所有的文件和文件夹到/usr/local/arm目录下。
否则到时候运行arm-linux-gcc hello.c会提示找不到stdio.h 或者 lib.so.6 等
HOWTO Use the GCC specs file
About Specs file
The "gcc" program invoked by users is a convenient front-end driver executable which will invoke other programs in the background such as cc1, as or ld to do its work according to the command line parameter given. A specs file is plain text used to control the default behavior for the "gcc" front-end. The specs file is usually built-in but for flexibility purposes, it can be overridden with an external version.
Basic Specs file modifications
CC will proce a specs file via the following command.
gcc -mpspecs > specs
You may use a text editor of your choice to inspect it. It may be confusing at first, but there are many places of interest. To use the specs file, invoke gcc with -specs= or place it at "/mingw/lib/gcc/mingw32//specs" to make GCC use it by default, where refers to the GCC version installed.
Adding include directories to the search path
& #160;he *cpp: section should be modified. It contains the following by default:
*cpp:
%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT}
If "z:\libx\include" needs to be added to the GCC includes search path, it should be changed to the following
*cpp:
%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} -I/z/libx/include
Adding lib directories to the search path
& #160;he *link_libgcc: section should be modified. It contains the following by default:
*link_libgcc:
%D
& #160;f "z:\libx\lib" needs to be added to the GCC library search path, it should be changed to the following
*link_libgcc:
%D -L/z/libx/lib
3. 如何在Ubuntu下建立交叉编译环境
1.安装交叉编译环境 sudo apt-get install gcc g++ libcc1 libg++ make gdb
2.安装交叉编译器 ftp://ftp.arm.linux.org.uk/pub/armlinux/toolchain/ 下载 cross -3.2.tar.bz2或者懒得去找干脆
wget ftp://ftp.arm.linux.org.uk/pub/armlinux/toolchain/ cross -3.2.tar.bz2
解压
sudo tar jxvf /home/zhaifang/cross -3.2.tar.bz2
sudo mv /home/zhaifang/usr/local/arm /usr/local
3.交叉编译器加入路径 sudo vi /etc/bash.bashrc后面加入
if [ -d /usr/local/arm ] ; then
PATH=/usr/local/arm/bin:"${PATH}"
fi
4.使环境生效 #source /etc/profile
5.检查 echo $PATH 出现/usr/local/arm/bin说明成功了
6.测试 arm-linux-gcc -v
4. 交叉编译时,如何链接指定路径下的库
在整个工程的configure.in文件中加入如下代码:
#configure.in
if test x$CC = xgcc; then
#AC_PATH_PROG(BLKID, blkid, [], [$PATH:/sbin])
#AC_PATH_PROG(VOLID, vol_id, [], [$PATH:/lib/udev])
AC_MSG_WARN($BLKID --------------------------------------) #code only for test
AM_CONDITIONAL(MY_CROSS_COMPILE,false)
else
#AC_PATH_PROG(BLKID, blkid, [], [/home/user-name/ltib/rootfs/sbin])
#AC_PATH_PROG(VOLID, vol_id, [], [/home/user-name/ltib/rootfs/lib])
AC_MSG_WARN($BLKID ++++++++++++++++++++++++++++++++++++++) #code 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
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
LDADD_common += -lblkid -luuid
endif
5. 如何交叉编译 动态库
首先,你要保证你编译的程序使用的交叉编译链是开发板支持的,例如arm-linux-4.3.2,一般是在虚拟机下面的linux系统下的/etc/profile里面添加编译链路径;接着,需要确保使用的内核是开发板目前使用的内核,一般MINI2440是使用linux-2.6.30版本的,这个要在程序的makefile文件里面改;还有,如果你使用静态编译方式文件会比较大,但是不用依赖库,如果是用动态编译,文件就比较小,但是依赖动态库,如果放到开发板上运行提示缺少动态库,就证明你没有把动态库放进开发板的/lib里面,可以用ldd指令查看需要哪些库;最后,记住移植的方式可以使用NFS或者TFTP,U盘也可以,放到开发板上后必须在文件存放的当前目录下./可执行文件,或者把文件放入/bin或者/sbin下面,就可以直接可执行文件,不用加./你可以在程序里面加些调试信息输出,例如printf,以此证明有执行。
6. python交叉编译失败怎么回事
1、在源码 python2.7.3/Moles/Setup.dist 搜索zlib ,打开该模块
2、继续下去,又提示缺少zlib.h,也就是我们的交叉编译库中缺少zlib头文件和库文件
3、在http://www.zlib.net/ 下载zlib源码,交叉编译zlib
由于zlib 编译不支持--host选项,所以在zlib目录下执行如下命令
~/zlib1.2.8/# mkdir _install
~/zlib1.2.8/#CC=arm-xxxxx(你的交叉编译器) ./configure --host=./_install(最好是绝对路径,我偷懒了,这个是安装目录)
~/zlib1.2.8/# make && make install
你会在_install目录下发现include 和 lib 目录
下一步,我们回到第1步
为了防止交叉编译链污染,我们在python目录下创建otherinclude otherlib
把zlib下的include和lib下的内容分别按照对应名字拷贝过来
4.在Moles/setup 找到我们前面setup.dist那句话,添加 -L../otherlib -I../otherinclude 这个应该都懂的
直接make
5,如果你之前make distclean过了,没有setup文件,请修改setup.dist.文件,重新configure!
