参考http://blog.chinaunix.net/uid-23089249-id-4762021.html
下载expect源码,tcl源码
先交叉编译tcl
cd /home/mit/update/tcl8.6.8/unix
CC=arm-poky-linux-gnueabi-gcc AR=arm-poky-linux-gnueabi-ar LD=arm-poky-linux-gnueabi-ld AS=arm-poky-linux-gnueabi-as ./configure -cache-file=cache0 --host=arm-poky-linux --prefix=/home/mit/update/tcl8.6.8/unix
结果报 C compiler cannot create executables
网上说要 apt-get install g++和apt-get install gcc libc6-dev 但其实不行,因为我是交叉编译
后来把CC=arm-poky-linux-gnueabi-gcc去掉
AR=arm-poky-linux-gnueabi-ar LD=arm-poky-linux-gnueabi-ld AS=arm-poky-linux-gnueabi-as ./configure -cache-file=cache0 --host=arm-poky-linux --prefix=/home/mit/update/tcl8.6.8/unix
得到Makefile文件,手动修改CC编译器为arm-poky-linux-gnueabi-gcc
make结果发现
/home/mit/update/tcl8.6.8/unix/tclUnixCompat.c:1005:5: error: impossible constraint in 'asm'
__asm__ __volatile__("mov %%ebx, %%esi \n\t" /* save %ebx */ ^
后来看了下源文件,把里面的代码注释了,直接返回TCL_OK
#if defined(HAVE_CPUID)
//#if defined(__x86_64__) || defined(_M_AMD64) || defined (_M_X64)
// __asm__ __volatile__("movq %%rbx, %%rsi \n\t" /* save %rbx */
// "cpuid \n\t"
// "xchgq %%rsi, %%rbx \n\t" /* restore the old %rbx */
// : "=a"(regsPtr[0]), "=S"(regsPtr[1]), "=c"(regsPtr[2]), "=d"(regsPtr[3])
// : "a"(index));
//#else
// __asm__ __volatile__("mov %%ebx, %%esi \n\t" /* save %ebx */
// "cpuid \n\t"
// "xchg %%esi, %%ebx \n\t" /* restore the old %ebx */
// : "=a"(regsPtr[0]), "=S"(regsPtr[1]), "=c"(regsPtr[2]), "=d"(regsPtr[3])
// : "a"(index));
//#endif
status = TCL_OK;
#endif
return status;
}
接着编译,发现编译成功后又调用了一个CONFIGURE文件,又在配置一个什么东西,但用的是gcc,不行还得在配置configure文件时就要是正确的,重新执行开始的
C=arm-poky-linux-gnueabi-gcc AR=arm-poky-linux-gnueabi-ar LD=arm-poky-linux-gnueabi-ld AS=arm-poky-linux-gnueabi-as ./configure -cache-file=cache0 --host=arm-poky-linux --prefix=/home/mit/update/tcl8.6.8/unix
后来去看了config.log,发现
/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find crt1.o: No such file or directory
/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find crti.o: No such file or directory
/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find crtbegin.o: No such file or directory
/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find -lstdc++
/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find -lm
/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find -lgcc_s
/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find -lgcc
/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find -lc
/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find -lgcc_s
/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find -lgcc
/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find crtend.o: No such file or directory
/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
后来猜是编译参数没有传对,自己手动交叉编译了下helloword程序
arm-poky-linux-gnueabi-g++ -o hello hello.o也是报的这个错,后来用别人提供的qt编译环境编译了下helloword程序
发现多了一些编译参数
arm-poky-linux-gnueabi-g++ -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/cortexa9hf-neon-poky-linux-gnueabi -c -pipe -g -std=gnu++0x -Wall -W -fPIC -I. -I../rootfs/usr/lib/glib-2.0/include -o hello.o hello.cpp
arm-poky-linux-gnueabi-g++ -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/cortexa9hf-neon-poky-linux-gnueabi -o hello hello.o
红色的是编译参数,把这些参数传configure文件调用
AR=arm-poky-linux-gnueabi-ar LD=arm-poky-linux-gnueabi-ld AS=arm-poky-linux-gnueabi-as ./configure CC=arm-poky-linux-gnueabi-gcc -cache-file=cache0 --host=arm-poky-linux --prefix=/home/mit/update/tcl8.6.8/unix CFLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/cortexa9hf-neon-poky-linux-gnueabi"
一切都好了
开始编译expect
CC=arm-poky-linux-gnueabi-gcc AR=arm-poky-linux-gnueabi-ar ./configure -cache-file=cache0 --host=arm-poky-linux --prefix=/home/mit/update/expect-5.45 CFLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/cortexa9hf-neon-poky-linux-gnueabi"
结果报错,看config.log 说expect不支持交叉编译,后来又看到别人的做是先不设置交叉编译参数,生成Makefile后再修改
./configure -cache-file=cache0 --prefix=/home/mit/update/expect-5.45 CFLAGS="--sysroot=/opt/fsl-imx-fb/4.1.15-2.1.0/sysroots/cortexa9hf-neon-poky-linux-gnueabi -D__ARM_PCS_VFP" --with-tclinclude=/home/mit/update/tcl8.6.8/unix/include
修改CC = arm-poky-linux-gnueabi-gcc AR=arm-poky-linux-gnueabi-ar 再把编译参数-march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9加到CFLAGS上
编译结果 链接时报错,找不到-lieee,上网上搜索了下不知道是什么库,直接在Makefile中删除了ieee的链接参数,再编译,没有报成功,但expect却编译出来了,放到arm上可以使用