如何交叉編譯開源庫-->編譯c-ares庫從失敗到成功的過程[ocean]



編譯c-ares庫從失敗到成功的過程
c-ares-master: apt-get install libtool   
####https://github.com/c-ares/c-ares

==============================


失敗的過程;

{
1.host配錯了
    ./configure --host=x86_64-pokysdk-linux --target=arm-poky-linux-gnueabi --prefix=/root/work/lib_arm/c-ares
    make
    
        root@ubuntu:~/work/share/mqtt/c-ares-master# find . -name "*.so*"
        ./.libs/libcares.so.2.2.0
        ./.libs/libcares.so
        ./.libs/libcares.so.2
        root@ubuntu:~/work/share/mqtt/c-ares-master# file ./.libs/libcares.so.2.2.0
        ./.libs/libcares.so.2.2.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=0e375b908f27eba4b86bd572c4716c1671b4b849, not stripped    

    
    
2. arm-poky-linux-gnueabi-gcc 交叉編譯工具的配置不適合代碼
ld: error: a.out uses VFP register arguments, /tmp/ccNTGLwS.o does not

    http://stackoverflow.com/questions/9753749/arm-compilation-error-vpf-registered-used-by-executable-not-object-file
    
    triplet indicates that your compiler is configured for the soft-float ABI.
    but part of your lib or *.o is using soft-float ABI.
    solved by exporting-mfloat-abi=hard to flags
    
    
    root@ubuntu:~/work/share/mqtt/c-ares-master# ./configure  --host=arm-poky-linux-gnueabi  --prefix=/root/work/lib_arm/c-ares
        checking whether to enable maintainer-specific portions of Makefiles... no
        checking whether make supports nested variables... yes
        checking whether to enable debug build options... no
        checking whether to enable compiler optimizer... not specified (assuming yes)
        checking whether to enable strict compiler warnings... no
        checking whether to enable compiler warnings as errors... no
        checking whether to enable curl debug memory tracking... no
        checking whether to enable hiding of library internal symbols... yes
        checking whether to expose internal static functions for testing... no
        checking for path separator... :
        checking for sed... /bin/sed
        checking for grep... /bin/grep
        checking for egrep... /bin/grep -E
        checking for arm-poky-linux-gnueabi-ar... /opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-ar
        checking for a sed that does not truncate output... (cached) /bin/sed
        checking whether to build with code coverage support... no
        checking build system type... x86_64-pc-linux-gnu
        checking host system type... arm-poky-linux-gnueabi
        checking for a BSD-compatible install... /usr/bin/install -c
        checking for arm-poky-linux-gnueabi-gcc... arm-poky-linux-gnueabi-gcc
        checking whether the C compiler works... no
        configure: error: in '/root/work/share/mqtt/c-ares-master':
        configure: error: C compiler cannot create executables
        See 'config.log' for more details        
            
            vi config.log    
                configure:4426: $? = 1
                configure:4445: checking whether the C compiler works
                configure:4467: arm-poky-linux-gnueabi-gcc    conftest.c  >&5
                /opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.1/
                ld: error: a.out uses VFP register arguments, /tmp/ccNTGLwS.o does not //重點在這里
                /opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.1/
                ld: failed to merge target specific data of file /tmp/ccNTGLwS.o
                collect2: error: ld returned 1 exit status
                configure:4471: $? = 1
                configure:4509: result: no
                configure: failed program was:
                | /* confdefs.h */
                | #define PACKAGE_NAME "c-ares"
                | #define PACKAGE_TARNAME "c-ares"
                | #define PACKAGE_VERSION "-"
                | #define PACKAGE_STRING "c-ares -"
                | #define PACKAGE_BUGREPORT "c-ares mailing list: http://cool.haxx.se/mailman/listinfo/c-ares"
                | #define PACKAGE_URL ""
                | #define OS "arm-poky-linux-gnueabi"
                | /* end confdefs.h.  */
                |
                | int main (void)
                | {
                |
                |  ;
                |  return 0;
                | }
                configure:4514: error: in '/root/work/share/mqtt/c-ares-master':
                configure:4516: error: C compiler cannot create executables
        

  解決辦法: CFLAGS加一個-mfloat-abi=hard  
}
View Code



正確步驟
{
    cd c-ares-master/
    ./buildconf   
    export CFLAGS="-mfloat-abi=hard -g0 -O2 -Wno-system-headers "
    ./configure  --host=arm-poky-linux-gnueabi  --prefix=/root/work/lib_arm/c-ares
    make

    root@ubuntu:~/work/share/mqtt/c-ares-master# find . -name "*.so*"
    ./.libs/libcares.so.2.2.0
    ./.libs/libcares.so
    ./.libs/libcares.so.2
    root@ubuntu:~/work/share/mqtt/c-ares-master# file ./.libs/libcares.so.2.2.0
    ./.libs/libcares.so.2.2.0: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=c170250d2d9eae99d07a9f71face684ee50c7ef7, not stripped
}


開源組件的常見配置:
{
查看目錄下面的README,INSTALL這些文檔,看怎么去build。
    ./buildconf
    ./configure --host=x86_64-pokysdk-linux --target=arm-poky-linux-gnueabi --prefix=/root/work/lib_arm/c-ares

make有時候可以手動指定CC,AR,LD等編譯選項,但是要根據組件的Makefile和config文件是否用到,名字是不是這個,不能隨意猜測
    make CC="arm-poky-linux-gnueabi-gcc" AR="arm-poky-linux-gnueabi-ar r" RANLIB="arm-poky-linux-gnueabi-ranlib"  
    make CC="arm-poky-linux-gnueabi-gcc" AR="arm-poky-linux-gnueabi-ar r" RANLIB="arm-poky-linux-gnueabi-ranlib" install

有可能需要配置下某些編譯選項以使得編譯器配置和組件代碼的要求相匹配
    export CFLAGS="-mfloat-abi=hard -g0 -O2 -Wno-system-headers "

}

 
參考:
build、host和target
http://www.cnblogs.com/electron/p/3548039.html    
{
  我們以 gcc 為例子來 講解 這三者的作用
  ./configure --build=編譯平台 --host=運行平台 --target=目標平台 [各種編譯參數]
  來配置gcc的源代碼,以讓其編譯出我們需要的gcc編譯器。

    --build:
        表示目前我們正在運行的平台名稱是什么,如果當前我們是在intel的pentium機器中編譯該系統,那么我們的--build就可能是 i686-pc-linux-gnu,當然如果我們在其它種類的機器上編譯那么這個build就應該是那個機器所對應的平台名稱。
        該參數在不指定的情況下將自動嘗試猜測目前平台的名稱。

    --host:
        表示我們把這個編譯好的gcc在什么樣的平台下運行,在交叉編譯過程中這個需要我們來指定,因為機器自己是不能知道我們心里是怎么想的,那 么我們可以明確的告訴它,我們要做出來的程序是運行在“龍芯”上的,但是目前還不能直接指定“龍芯”,因此我們這里指定為mips64el- unknown-linux-gnu(如果你省點事情那么就用這個名字好了,如果你想用個有個性的名字,那么請你想明白它的含義再動手,並且做好后面的過 程需要多出一些手續的麻煩的心理准備)。
        --host也可以不指定,那么host將自動使用build來定義自己,不過那將不再是交叉編譯。
        注:--build和--host在不同的時候就被配置文件認定為交叉編譯方式。

    --target:
        該參數的目的是讓配置程序知道這個軟件被編譯后使用來處理什么平台上的文件的。

    總結一下:
        build:自動測試在用平台名稱,若無法檢測出來則需要指定。
        host:若無指定,自動使用build的結果。
        build和host相同時表示本地編譯,若不相同則表示交叉編譯。
        target:表示需要處理的目標平台名稱,若無指定使用host相同名稱,gcc、binutils等於平台指令相關軟件有此參數,多數軟件此參數無用處。        
        
}










免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM