交叉編譯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!
