解决“C compiler cannot create executables”的错误

感觉不错的解决方法,还没有尝试过,先转载下来了。

解决“C compiler cannot create executables”的错误
Posted on 2006-09-25 by hilyjiang

作者:Hily 原始链接:http://hily.me/blog/2006/09/minigui-compile-error/
版权声明:可以转载,转载时务必以超链接形式标明文章原始出处和作者信息及版权声明

miniGUI 1.3.3中“Development environment options”的配置如下:

  │ │  (uClinux) Platform                                           │ │
  │ │  (arm-elf-gcc) Compiler                                       │ │
  │ │  (uClibc) Libc                                                │ │
  │ │  --- Compilation and installation options                     │ │
  │ │       uClinux dist directory: "/opt/uClinux/uClinux-dist"     │ │
  │ │  [ ] Choose different uClibc directory                        │ │
  │ │  --- Installation options                                     │ │
  │ │       Path prefix: "/usr/local"                               │ │
  │ │  --- Additonal Compiler Flags                                 │ │
  │ │       CFLAGS: ""                                              │ │
  │ │       LDFLAGS: ""                                             │ │

配置完后,保存配置时出错:

Saving your MiniGUI configuration...
install prefix = /usr/local
compiler = arm-elf-gcc
target = arm-elf-linux
host = arm-elf-linux
CFLAGS = -Os -D__uClinux__ -fno-builtin -I/home/work1/uClinux-dist-server/linux-2.4.x/include -I/home/work1/uClinux-dist-server/lib/uClibc/include -I/home/work1/uClinux-dist-server/lib/uClibc/include/../ -D__PIC__ -fpic -msingle-pic-base
LDFLAGS = -Wl,-elf2flt -Wl,-move-rodata -L/home/work1/uClinux-dist-server/lib/uClibc/lib -L/home/work1/uClinux-dist-server/lib/uClibc/lib/../ -lc
checking build system type... i386-pc-linux-gnu
checking host system type... arm-elf-linux-gnu
checking target system type... arm-elf-linux-gnu
checking for arm-elf-linux-gcc... arm-elf-gcc
checking for C compiler default output... configure: error: C compiler cannot create executables
See `config.log' for more details.

*** End of MiniGUI configuration.
*** Next, you must run 'make'.

花了大半天查错,终于找到答案。

查看config.log出错的地方为:

     95 configure:2069: checking for C compiler default output
     96 configure:2072: arm-elf-gcc    conftest.c  >&5
     97 /usr/local/lib/gcc-lib/arm-elf/2.95.3/libgcc.a(__main.o)(.text+0xc4): In function `__do_global_ctors':
     98 : undefined reference to `__CTOR_LIST__'
     99 /usr/local/lib/gcc-lib/arm-elf/2.95.3/libgcc.a(__main.o)(.data+0x0): undefined reference to `__DTOR_LIST__'
    100 collect2: ld returned 1 exit status
    101 configure:2075: $? = 1

看到96行arm-elf-gcc的编译选项居然为空,不解。。
查看configure中2072行附近:

echo "$as_me:$LINENO: checking for C compiler default output" >&5
echo $ECHO_N "checking for C compiler default output... $ECHO_C" >&6
ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
if { (eval echo "$as_me:$LINENO: \"$ac_link_default\"") >&5
  (eval $ac_link_default) 2>&5
  ac_status=$?
  echo "$as_me:$LINENO: \$? = $ac_status" >&5
  (exit $ac_status); }; then

其中ac_link在1716行定义:

ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'

奇怪的是CFLAGS居然是空的,在保留配置时明明看到有给CFLAGS赋值:

CFLAGS = -Os -D__uClinux__ -fno-builtin -I/home/work1/uClinux-dist-server/linux-2.4.x/include -I/home/work1/uClinux-dist-server/lib/uClibc/include -I/home/work1/uClinux-dist-server/lib/uClibc/include/../ -D__PIC__ -fpic -msingle-pic-base

看看到底是怎么保存的,scripts/Menuconfig中:

   1412 #
   1413 # Confirm and Save
   1414 #
   1415 if $DIALOG --backtitle "$backtitle" \
   1416            --yesno "Do you wish to save your new MiniGUI configuration?" 5 60
   1417 then
   1418         save_configuration
   1419         scripts/mkconfig
   1420         ./config-mnu
   1421         #rm config-mnu

保存时运行了scripts/mkconfig和./config-mnu,config-mnu是在mkconfig中生成的。而. /configure是在config-mnu中运行的,但是在config-mnu中却没有CFLAGS的设置。检查config-mnu,当我看到这几行时,我真的又想杀人了:

    189     echo "CC=$CC \\" >> $CONFIG_MNU
    190     #echo "CFLAGS=\"$CFLAGS\" \\" >> $CONFIG_MNU
    191     #echo "LDFLAGS=\"$LDFLAGS\" \\" >> $CONFIG_MNU
    192     echo "./configure \\" >> $CONFIG_MNU

好好的,谁把它们注释掉了!
把注释的那两行恢复一下就通过了。

– EOF –
This entry was posted in 嵌入式. Bookmark the permalink.

你可能感兴趣的:(C++,c,linux,C#,gcc)