Cygwin下用crosstool-ng 编译交叉工具链的常见错误及解决办法
crosstool编译过程中gcc版本问题

crosstool编译过程中gcc版本问题crosstool编译过程中gcc版本问题在使用crosstool构建工具链的过程中,出现了如下问题,导致arm-linux-gcc没有生成:> checking version of gcc... 4.0.0, bad> checking for gnumake... no> checking for gmake... gmake> checking version of gmake... 3.80, ok> configure: error:> *** These critical programs are missing or too old: gcc> *** Check the INSTALL file for required versions.察看crosstool目录中的contrib/inbox.txt文件,有关于这个问题的邮件描述:> checking build system type... i686-pc-linux-gnu> checking host system type... mipsel-unknown-linux-gnu > checking sysdep dirs... sysdeps/mips/elf sysdeps/unix/sysv/linux/mips> sysdeps/unix/sysv/linux sysdeps/gnu sysdeps/unix/common> sysdeps/unix/mman sysdeps/unix/inet sysdeps/unix/sysv sysdeps/unix/mips> sysdeps/unix sysdeps/posix sysdeps/mips/mipsel sysdeps/mips/fpu> sysdeps/mips sysdeps/wordsize-32 sysdeps/ieee754/flt-32> sysdeps/ieee754/dbl-64 sysdeps/ieee754 sysdeps/generic/elf sysdeps/generic> checking for a BSD-compatible install... /usr/bin/install -c > checking whether ln -s works... yes> checking for pwd... /bin/pwd> checking for mipsel-unknown-linux-gnu-gcc... gcc> checking version of gcc... 4.0.0, bad> checking for gnumake... no> checking for gmake... gmake> checking version of gmake... 3.80, ok> configure: error:> *** These critical programs are missing or too old: gcc> *** Check the INSTALL file for required versions.>I have had the same problem. What I found was that the glibc configurescript was testing for a version of gcc 3.2.* or later. It does not testfor a major number above 3 so the test fails. I do not know where thistest is initiated, but once you have reached that point you can patchthe configure script and run demo-*.sh with the --nounpack option addedto your desired toolchain build.This patch worked for me:--- configure.orig 2005-09-19 21:31:45.000000000 -0400 +++ configure 2005-09-19 21:32:13.000000000 -0400@@ -2274,6 +2274,8 @@'') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;3.[2-9]*)ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;+ 4.*)+ ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;*) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;esacI hope that this helps. Good Luck.-Mike Joyce其意思就是说,在glibc的configure脚本里会检查gcc的版本,当不是需要的版本就保错, glibc的configure中有如下检查:if test -z "$CC"; thenac_verc_fail=yeselse# Found it, now check the version.echo "$as_me:$LINENO: checking version of $CC" >&5echo $ECHO_N "checking version of $CC... $ECHO_C" >&6 ac_prog_version=`$CC -v 2>&1 | sed -n 's/^.*version \([egcygnustpi-]*[0-9.]*\).*$/\1/p'`case $ac_prog_version in'') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;3.[2-9]*)ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;*) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;esacecho "$as_me:$LINENO: result: $ac_prog_version" >&5echo "${ECHO_T}$ac_prog_version" >&6fiif test $ac_verc_fail = yes; thencritic_missing="$critic_missing gcc"fi在上面的gcc版本检查中,只使用了模式3.[2-9]*即只支持3.xxx 版本的gcc,在crosstool自己的patches目录下有一个patch:patches/glibc-2.3.3-allow-gcc-4.0-configure.patch,他会在编译glic-2.3.2的时候给这个configure文件先打补丁,那个补丁来修复这个bug,但是这个补丁文件也不是很好,其内容是:--- glibc-2.3.3/configure.old Mon Mar 14 12:01:10 2005+++ glibc-2.3.3/configure Mon Mar 14 12:02:03 2005@@ -3899,7 +3899,7 @@ac_prog_version=`$CC -v 2>&1 | sed -n 's/^.*version \([egcygnustpi-]*[0-9.]*\).*$/\1/p'`case $ac_prog_version in'') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;- 3.[2-9]*)+ 3.[2-9]*|4.[01]*)ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;*) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;即,它只是增加了对4.0xxx或者4.1xxx的支持,还是不够,我现在用的是4.2.1因此还是会出错,因此,修改这个patch,改为3.[2-9]*|4.*)就可以过去了。
Cygwin问题及解答

Cygwin问题及解答1. 关于Cygwin1.1.Cygwin是什么?1.2.Windows系统都支持哪些版本?1.3.哪里可以下载到??1.4.Cygwin是免费软件吗?1.5. 如何知道自己使用的Cygwin版本?1.6. 哪些人在默默支持的cygwin?2. 安装 Cygwin2.1. 安装过程有何建议或注意事项?2.2. Cygwin自动安装是怎样的过程?2.3. 可以用命令行setup.exe运行安装吗?2.4. 为什么不安装在C:\根目录下?2.5. 可以通过Cygwin 安装程序下载旧版本的吗(例如:gcc-2.95)?2.6. 在升级把cygwi1.5升级到1.7后, user mount 没了?我如何恢复这命令的使用?2.7. Cygwin 安装程序或者组件包会被病毒感染吗?2.8. 在运行Cygwin安装程序时,电脑死机了!!2.9. 我应该下载哪些程序包?哪些是’make’,’gcc’,’vi’等等?2.10. 我想让很好的运行Cygwin,我应该如何去下载各种cygwin 组件?2.11. Cygwin需要多大硬盘空间?2.12. 哪里可以找到我需要升级的软件版本?2.13. 如果安装失败了,如何处理?2.14. 我通过终端服务安装时报错了。
我应该如何处理?2.15. Windows系统用户名有一个空格,会有什么问题吗?2.16. 我的个人用户环境变量需要进行修改。
2.17. 如何单独卸载Cygwin的组件包?2.18. 如何卸载Cygwin服务?2.19. 如何卸载全部的Cygwin?2.20. 如何安装截屏?2.21. Cygwin安装程序可以维护下载镜像站点吗?2.22. 如何做一张便携式Cygwin的CD光盘?2.23. 如何保存,恢复,删除或者修改Cygwin注册信息?3. 更多的资料3.1. 哪里可以找到Cygwin的文档?3.2. 可以订阅Cygwin的邮件吗?3.3. 如果有问题如何去做或者通过订阅邮件回答问题?4. Cygwin的使用4.1. 为什么我的程序会提示无法发现cygncurses-8.dll? 或cygintl-3.dll? 或 cygreadline6.dll? 或…?4.2. 为什么Cygwin突然运行很慢?4.3. 为什么我不能访问网络共享?4.4. 我应该如何设置路径PATCH?4.5. 脚本 (或另外一个shell) 提示 "command not found", 但是我并没有打错命令!4.6. 我如何转换Windows和unix的路径??4.7. 为什么在启动程序时,脚本不读取.bashrc文件?4.8. 我如何得到一个大小写不敏感的完整脚本文件名?4.9. 我可以使用包含空格的路径或者文件名吗?4.10. 为什么不能使用cd命令进入一个短名称的目录?4.11. 我有一个关于findingling的基本问题,如何使用?4.12. “su”命令为什么不可用?4.13. 为什么“man –k”(或者apropos)命令不能运行?4.14. 为什么“chmod”命令不能运行?4.15. 为什么shell脚本不运行?4.16. 在Cygwin环境下如何使用print?4.17. 为什么不支持多国语言(unicode)字符?4.18. 我的程序在输出多国语言字符时,仅能看到一些灰色的方块?4.19. 可以一次复制多个DLL文件吗?4.20. 我已经看了以上的所有问题,但是我想要我想把Cygwin和某产品捆绑起来并把此程序移植到顾客的站点上。
最常见的20种VC++编译错误信息与解决方法(转)

最常见的20种VC++编译错误信息与解决⽅法(转)1、fatal error C1010: unexpected end of file while looking for precompiled header directive。
寻找预编译头⽂件路径时遇到了不该遇到的⽂件尾。
(⼀般是没有#include "stdafx.h")1、如果发⽣错误的⽂件是由其他的C代码⽂件添加进⼊当前⼯程⽽引起的,则Alt+F7进⼊当前⼯程的 Settings,选择C/C++选项卡,从Category组合框中选中Precompiled Headers,选择Not Using Precompiled headers。
确定。
2、在⽂件开头添加: #include "stdafx.h"2、fatal error C1083: Cannot open include file: 'R…….h': No such file or directory.不能打开包含⽂件“R…….h”:没有这样的⽂件或⽬录。
3、error C2011: 'C……': 'class' type redefinition类“C……”重定义。
4、error C2018: unknown character '0xa3'不认识的字符'0xa3'。
(⼀般是汉字或中⽂标点符号)5、error C2057: expected constant expression希望是常量表达式。
(⼀般出现在switch语句的case分⽀中)6、error C2065: 'IDD_MYDIALOG' : undeclared identifier“IDD_MYDIALOG”:未声明过的标识符。
7、error C2082: redefinition of formal parameter 'bReset'函数参数“bReset”在函数体中重定义。
交叉编译器的制作

交叉编译器的制作交叉工具链制作至尊宝典一些必须知道的基础知识Debian 操作系统以及aptitude 命令autoconf and automake什么是交叉编译,configure 的几个参数build host targetbuild:编译代码的机器,的CPU指令集host:编译生成的东西,的CPU指令集(目标板上的CPU的指令集)target:编译生成的东西,他编译生成的的东西,的指令集(所以此选项一般不用,大多只有在做交叉工具链时使用)0、以Expert mode 安装Debian不要升级,确保环境是一个纯净的环境1、声明环境变量1export IS_TARGET=arm-linux1export DIR_SRC=/root/cross_toolchains/src1export PREFIX=/opt/cross_toolchains/arm1export CONFIGURE_BASE="../configure --prefix=$PREFIX --with-sysroot=$PREFIX"2、下载制作交叉工具链所必须的的代码1binutils1ftp:///doc/e613296072.html,/gnu/bi nutils/binutils-2.21.tar.gz1gcc1ftp:///doc/e613296072.html,/gnu/g mp/gmp-5.0.2.tar.gz1ftp:///doc/e613296072.html,/gnu/mpfr/mpfr-3.0.1.tar.gz1/doc/e613296072.html,/mpc/downlo ad/mpc-0.9.tar.gz1ftp:///doc/e613296072.html,/gnu/gc c/gcc-4.6.1/gcc-4.6.1.tar.gz1glibc1ftp:///doc/e613296072.html,/gnu/gli bc/glibc-2.14.tar.gz1ftp:///doc/e613296072.html,/gnu/gli bc/glibc-ports-2.13.tar.gz1linux kernel1/doc/e613296072.html,/pub/linux/k ernel/v2.6/linux-2.6.39.2.tar.bz2 3、安装(卸载)必要的的软件包1aptitude install build-essential automake bison flex texinfo gawk g\+\+1aptitude remove mawk4、解压、归档软件包1cd $DIR_SRC1tar -xf binutils-2.21.tar.gz1tar -xf gmp-5.0.2.tar.gz1tar -xf mpc-0.9.tar.gz1tar -xf mpfr-3.0.1.tar.gz1tar -xf gcc-4.6.1.tar.bz21tar -xf glibc-2.14.tar.gz1tar -xf glibc-ports-2.13.tar.gz1tar -xf linux-2.6.39.2.tar.bz21mv gmp-5.0.2 gcc-4.6.1/gmp1mv mpc-0.9 gcc-4.6.1/mpc1mv mpfr-3.0.1 gcc-4.6.1/mpfr1mv glibc-ports-2.13 glibc-2.14/ports5、编译BINUTILS1cd $DIR_SRC1cd binutils-2.211mkdir build1cd build1$CONFIGURE_BASE --target=$IS_TARGET --disable-nls --enable-shared--disable-multilib1make configure-host1make1make install1export PATH=$PATH:$PREFIX/bin问题:编译binutils一般不会遇到什么问题,但是,如果前面步骤3中安装的软件不全会出现问题6、建立用于编译C库的GCC 1cd $DIR_SRC1cd gcc-4.6.11mkdir build1cd build1$CONFIGURE_BASE \1--target=$IS_TARGET \1--disable-nls \1--disable-shared \1--without-headers \1--with-newlib \1--enable-languages=c \1--disable-threads \1--disable-multilib \1--disable-decimal-float \1--disable-libgomp \1--disable-libmudflap \1--disable-libssp1make all-gcc all-target-libgcc1make install-gcc install-target-libgcc1值得注意的几个configure选项1--target1--disable-shared1--without-headers1--with-newlib1--enable-language-c1--disable-thread1cd $PREFIX/lib/gcc/$IS_TARGET/4.6.11ln -s libgcc.a libgcc_eh.a1有建议修改 gcc/config/t-linux 这个文件1增加-D__gthr_posix_h -Dinhibit_libc 两个宏,但我这里没这样做,是因为:1在configure后,编译使用的命令并不是make 或者是make all 而是 make all-gcc 和 make all-target-libgcc,所以很多问题不会出现1-with-newlib,这个选项不会迫使我们必须使用newlib1libgcc.mvars: No such file or directory1不能在GCC 的源代码目录进行configure,必须在另外的目录进行configure make 等工作1所以这里在代码所在目录下mkdir build 并cd build 再进行 ../configure 等工作1configure: error: C compiler cannot create executables1如果使用 make 或 make all 会出现这样的问题,因为我们还未编译出目标指令集的 C库1所以只能先使用 make all-gcc make all-target-libgcc1../../../../arm-linux/bin/ld: cannot find -lgcc1../../../../arm-linux/bin/ld: cannot find -lgcc_eh1很多资料都只写了make all-gcc 而没有写make all-target-libgcc 这样只建立了gcc,没有建立libgcc.a会出现以上第一个错误1如果没手工建立链接文件 libgcc_eh.a 则会出现第二个错误7、配置内核生成必要的头文件1cd $DIR_SRC1cd linux-2.6.39.21make ARCH=arm CROSS_COMPILE=$IS_TARGET- menuconfig1make ARCH=arm CROSS_COMPILE=$IS_TARGET-1mkdir -p $PREFIX/include1cd $PREFIX/include1ln -s $DIR_SRC/linux-2.6.39.2/arch/arm/include/asm asm 1ln -s $DIR_SRC/linux-2.6.39.2/include/linux linux1ln -s $DIR_SRC/linux-2.6.39.2/include/asm-generic asm-generic1这里并没有将内核的头文件复制到交叉工具链的安装目录1编译C库的时候,需要对应的CPU指令集的汇编代码所以做了链接处理1编译内核在执行make ARCH=arm CROSS_COMPILE=$IS_TARGET- 时如果出错,是没有关系的,这里只要生成了对应的 version.h autoconf.h就可以了8、编译C库1cd $DIR_SRC1cd glibc-2.91mkdir build1cd build1vi ../configure1vi ../ports/sysdeps/unix/sysv/linux/arm/sigrestorer.S1vi ../sysdeps/unix/syscall-template.S1vi ../nptl/allocatestack.c1vi ../elf/dl-tls.c1vi ../sysdeps/ieee754/dbl-64/s_fma.c1vi ../sysdeps/ieee754/dbl-64/s_fmaf.c11具体的修改,我写在下面(觉得还是要说清楚为什么修改,所以就没用sed命令或是做一些patch文件了,请向下看)1CC=$IS_TARGET-gcc \1$CONFIGURE_BASE \1--host=$IS_TARGET \1-enable-add-ons \1--with-binutils=$PREFIX/bin \1--with-headers=$PREFIX/include \1libc_cv_forced_unwind=yes \1libc_cv_c_cleanup=yes1值得注意的几个configure选项1--host1--with-headers1lib_cv_forced_unwind1lib_cv_c_cleanup1make1make install1这里编译的时候并有选择TARGET为EABI,所以在制作交叉工具链时会有很多问题需要修改1*** These critical programs are missing or too old: as ld1*** Check the INSTALL file for required versions.1vi ../configure1查找 "$AS --version" 将 2.1[3-9] 修改为 2.[1-2][0-9]1查询 "$LD --version" 将 2.1[3-9] 修改为 2.[1-2][0-9]1Error: previous CFI entry not closed (missing .cfi_endproc) 1vi ../ports/sysdeps/unix/sysv/linux/arm/sigrestorer.S1ENTRY(__default_sa_restorer) 下增加1END(__default_sa_restorer)1ENTRY(__default_rt_sa_restorer) 下增加1END(__default_rt_sa_restorer)1syscall-template.S:82: Error: CFI instruction used without previous .cfi_startproc1vi ../sysdeps/unix/syscall-template.S1这个问题的修改我也不是十分确定,我是这样来思考的1看到 syscall-template.S 中有 #include1去查看 ports/sysdeps/unix/sysv/linux/arm/sysdep.h1看到如下代码1#ifdef __ASSEMBLER__1#undef PSEUDO11#define PSEUDO(name, syscall_name, args) \1 .text;\1 ENTRY (name);\1 DO_CALL (syscall_name, args); \1 cmn r0, $4096;11猜测是__ASSEMBLER__宏未打开,以至于未能找到PSEUD0函数的声明,则将11#define PSEUDO(name, syscall_name, args) \1 .text;\1 ENTRY (name);\1 DO_CALL (syscall_name, args); \1 cmn r0, $4096;11这段代码添加至 ../sysdeps/unix/syscall-template.S 中1LS_DTV_UNALLOCATED undeclared (first use in this function)1vi ../nptl/allocatestack.c1vi ../elf/dl-tls.c1这个错误会出现在编译以上两个文件的时候,这个宏的定义我grep了整个glibc的所有代码,没找到ARM相关的声明及定义,按照其他指令集的定义猜测着修改如下1在以上两个C文件中增加相应的定义11#define TLS_DTV_UNALLOCATED ((void *) -1l)1E_TOWARDZERO undeclared (first use in this function)1E_INEXACT undeclared (first use in this function)1以上两个错误会出现在以下两个文件的的编译过程中1vi ../sysdeps/ieee754/dbl-64/s_fma.c1vi ../sysdeps/ieee754/dbl-64/s_fmaf.c1参考 ports/sysdeps/arm/eabi/bits/fenv.h中的定义1在两个文件中添加1#define FE_TOWARDZERO 0xc000001#define FE_INEXACT 161mawk: scripts/gen-sorted.awk: line 19: regular expression compile failed1所以要 aptitude install gawk 所以也顺带着 aptitude remove mawk1configure: error: forced unwind support is required1configure 中增加配置参数 libc_cv_forced_unwind=yes1error: the compiler must support C cleanup handlin1configure 中增加配置参数libc_cv_c_cleanup=yes1--enable-add-ons 为 C 库增加 thread 支持,目前默认使用的是 nptl 所以这里没有去下载 glibc-threads 相关的代码1--with-headers 指定内核头文件所在的目录9、编译完整的gcc 工具链1mkdir -p $PREFIX/usr1cd $PREFIX/usr1ln -s ../include include1cd $PREFIX1mkdir -p opt/cross_toolchains1cd opt/cross_toolchains/1ln -s ../../../arm arm1cd $DIR_SRC1cd gcc-4.6.11cd build1make clean1make distclean1rm * -rf1$CONFIGURE_BASE \1--target=arm-linux \1--enable-languages=c,c++ \1--enable-shared \1--disable-nls \1--enable-c99 \1--enable-long-long \1--disable-multilib \1--enable-__cxa_atexit1几个值得注意的configure 选项1--target1--enable-shared1make1make install1The directory that should contain system headers does not exist:1这个问题我没具体的去跟踪了,从表面上看出来是一些路径上的问题,并且经过验证,这个问题是在configure时使用了--with-sysroot选项时产生的1为了尝试不通过建立链接的方式去解决这个问题1在指明了 --includedir --libdir --sysconfdir 等等一系列参数后编译,依然会出现此问题1所以不再跟踪,暂且是当做GCC编译环境上的一个 BUG好了1/opt/cross_toolchains/arm/arm-linux/bin/ld: cannot find/opt/cross_toolchains/arm/lib/libc.so.6 inside /opt/cross_toolchains/arm 1这个问题更是有点神经病了,所以这里也不跟踪了,也是由于使用了 --with-sysroot选项产生的问题,建立了第二个链接文件1目的是让 /opt/cross_toolchains/arm 这个被当做是根目录的目录里面能有一个跟--prefix 指定的/opt/cross_toolchains/arm 一样的目录结构(说起来真别扭)参考资料https:///doc/e613296072.html,/devel operworks/cn/linux/l-embcmpl//doc/e613296072.html,/view/clfs-embedded/arm/cross-tools/introduction.html/doc/e613296072.html,/bbs/showthre ad.php?t=267672(这个文章虽然有点老,也有点神,把一些能看懂的说的让人看不懂,那个图更是让人觉得,汗,但原理还是说的很清楚的,这里强调的--with-sysroot的3次出现的问题,还是值得仔细想想的,这也是我为什么将--with-sysroot 选项做到$CONFIGURE_BASE 这个环境变量中的原因)。
交叉工具链编译

交叉工具链编译随着计算机科技的快速发展,软件开发领域也日益壮大。
为了满足不同平台或架构的需求,开发人员需要使用交叉工具链进行编译。
本文将介绍交叉工具链编译的概念、作用、使用场景以及一些常见的交叉工具链。
一、概念与作用交叉工具链是一套用于在一种平台上生成另一种平台上可执行文件的工具集合。
它通常包含编译器、链接器、调试器等工具,用于将源代码编译成可在目标平台上运行的二进制文件。
交叉工具链的主要作用是实现不同平台之间的代码移植。
通过使用交叉工具链,开发人员可以在一种平台上编写代码,并在其他不同的平台上编译、运行和调试代码,从而实现跨平台的开发和部署。
二、使用场景1. 嵌入式系统开发:嵌入式系统通常使用特定的硬件平台,开发人员需要使用交叉工具链将代码编译成适配该硬件平台的可执行文件。
例如,开发人员可以在Windows平台上编写代码,然后使用交叉工具链将代码编译成适用于ARM处理器的可执行文件。
2. 跨平台开发:在开发跨平台应用程序时,开发人员可以使用交叉工具链将代码编译成多个平台上的可执行文件。
例如,使用交叉工具链可以将C语言代码编译成在Windows、Linux和MacOS上都能运行的可执行文件。
3. 调试与优化:交叉工具链还可以用于调试和优化代码。
开发人员可以使用交叉工具链在目标平台上进行调试,以便更好地理解代码在不同平台上的行为,并进行性能优化。
三、常见的交叉工具链1. GCC:GNU编译器套件(GNU Compiler Collection)是一个广泛使用的开源编译器套件,包括C、C++、Fortran等编译器。
GCC支持多种平台和架构,可以用于交叉编译。
2. Clang:Clang是一个基于LLVM的C语言家族编译器,具有高速、低内存占用和模块化等特点。
Clang也支持交叉编译,可以生成适用于多种平台的可执行文件。
3. Visual Studio:微软的Visual Studio开发工具套件也提供了交叉编译的支持。
常见gcc 编译错误整理

常见gcc 编译错误整理常见gcc 编译错误整理(开始) 11 error: expected expression before 'else' else之前无表达式。
2 error: lvalue required as left operand of assignment 左值问题。
3 error: invalid storage class for function 'XXXXXX' 在文件的某个地方,丢失了一个大括号‘}’。
常见gcc编译警告整理(开始)1、warning: no newline at end of file 在文件最后一行加上回车键解释:在《Rationale for the C99 standard》一文中,有C99的相关信息:A backslash immediately before a newline has long been used to continue string literals, as well as preprocessing command lines. In the interest of easing machine generation of C, and of transporting code to machines with restrictive physical line lengths, the C89 Committee generalized this mechanism to permit any token to be continued by interposing abackslash/newline sequence.c/c++代码的每一行后面有一个“结束符”,也就是newline。
避免当被include的文件展开后,前一个文件的最后一行与后一个文件的第一行直接被连接成一行从而造成错误。
汇编常见错误解决方法总结

汇编常见错误解决⽅法总结汇编常见错误总结Block nesting error嵌套出错.嵌套的过程,段,结构,宏指令或重复块等⾮正常结束.例如在嵌套语句中有外层的结束语句,⽽⽆内层的结束语局1Extra characters on line⼀语句⾏有多余字符,可能是语句中给出的参数太多2Internal error-Register already defined这是⼀个内部错误.如出现该错误,请记下发⽣错误的条件,并使⽤Product Assistance Request 表与Microsoft公司联系3Unkown type specifer未知的类型说明符.例如类型字符拼错,把BYTE写成BIT,NEAR写成NAER等4Redefinition of symbol符号重定义.同⼀标识符在两个位置上定义.在汇编第⼀遍扫描时,在这个标识符的第⼆个定义位置上给出这个错误5Symbol is multidefined符号多重定义.同⼀标识符在两个位置上定义.在汇编第⼆遍扫描时,每当遇到这个标识符都给出这个错误6Phase error between passes两次扫描间的遍错.⼀个标号在⼆次扫描时得到不同的地址值,就会给出这种错误.若在启动MASM时使⽤/D 任选项,产⽣第⼀遍扫描的列表⽂件,它可帮助你查找这种错误7Already had ELSE clause已有ELSE语句.在⼀个条件块⾥使⽤多于⼀个的ELSE语句8Must be in conditional block没有在条件块⾥.通常是有ENDIF或ELSE语句,⽽⽆IF 语句9Symbol not defined符号未定义,在程序中引⽤了未定义的标识符10Syntax error语法错误.不是汇编程序所能识别的⼀个语句11Type illegal in context指定⾮法类型.例如对⼀个过程指定BYTE类型,⽽不是NEAR或FAR12Group name must be unique组名应是唯⼀的.作为组名的符号作为其他符号使⽤13Must be declared during pass 1必须在第⼀遍扫描期间定义.在第⼀遍扫描期间,如⼀个符号在未定义前就引⽤,就会出现这种错误.14Illegal public declaration⼀个标识符被⾮法的指定为PUBLIC类型15Symbol already defferent kind重新定义⼀个符号为不同种类符号.例如⼀个段名重新被当作变量名定义使⽤16Reserved word used as symbol把汇编语⾔规定的保留字作标识符使⽤17Forward reference illegal⾮法的向前引⽤.在第⼀遍扫描期间,引⽤⼀个未定义符号.18Operand must be register操作数位置上应是寄存器,但出现了标识符19Wrong type of register使⽤寄存器出错20Operand must be segment or group应该给出⼀个段名或组名.例如ASSUME语句中应为某段寄存器和指定⼀个段名或组名,⽽不应是别的标号或变量名等21Symbol has no segment不知道标识符的段属性22Operand must be type specifierSymbol alread defined locally以被指定为内部的标识符,企图在EXTRN语句中⼜定义外部标识24Segment paraneters are changed段参数被改变.如同⼀标识符定义在不同段内25Improper align/combin type段定义时的定位类型/组合类型使⽤出错26Reference to multidefined symbol指令引⽤了多重定义的标识符27Operand expected需要⼀个操作数,只有操作符28Operator expected需要⼀个操作符,但只有操作数29Divdsion by 0 or overflow除以0或溢出30Negative shift count运算符SHL或SHR的移位表达式值为负数31Operand type must match操作数类型不匹配.双操作数指令的两个操作数长度不⼀致,⼀个是字节,⼀个是字32Illegal use of external外部符号使⽤出错33Must be record field name应为记录字段名.在记录字段名位置上出现另外的符号34Must be record name or field name应为记录名或记录字段名.在记录名或记录字段名位置上出现另外的符号35Operand must be sizeMust be variable,label,or constant应该是变量名,标号,或常数的位置上出现了其他信息37Must be stucture field name应该为结构字段名.在结构字段名位置上出现了另外的符号38Lefe operand must segment操作数的左边应该是段的信息.如设DA1,DA2均是变量名,下列语句就是错误的:"MOV AX,DA1:DA2".DA1位置上应使⽤某段寄存器名39One operand must constant操作数必须是常数.40Operand must be in same segment or one constant"—"运算符⽤错.例如"MOV AL,—VAR",其中VAR是变量名,应有⼀常数参加运算.⼜如两个不同段的变量名相减出错41Normal type operand expected要求给出⼀个正常的操作数.42Constant expected要求给出⼀个常数.43Operand must have segment运算符SEG⽤错.44Must be associated with data在必须与数据段有关的位置上出现了代码段有关的项45Must be associated with code在必须与代码段有关的位置上出现了数据段有关的项46Multiple base registers同时使⽤了多个基址寄存器.如"MOV AX ,[SI][BP]"47Multiple index registers同时使⽤了多个变址寄存器.如"MOV AX ,[SI][DI]"指令仅要求使⽤基址寄存器或变址寄存器,⽽不能使⽤其他寄存器.49Illegal use of register⾮法使⽤寄存器出错50Value is out of range数值太⼤,超过允许值.例如:"MOV AL ,100H"51Operand not in current CS ASSUME segment操作数不在当前代码段内.通常指转移指令的⽬标地址不在当前CS段内52Improper operand type操作数类型使⽤不当.例如:"MOV VAR1,VAR2".两个操作数均为存储器操作数,不能汇编出⽬标代码53Jump out of range by %ld byte条件转移指令跳转范围超过-128~ 127个字节.出错⼚,信息同时给出超过的字节数54Index displacement must be constant变址寻址的位移量必须是常数55Illegal register value⾮法的寄存器值.⽬标代码中表达寄存器的值超过756Immediate mode illegal不允许使⽤⽴即数寻址.例如"MOV DS,CODE"其中CODE是段名,不能把段名作为⽴即数传送给段寄存器DS 57Illegal size for operand使⽤操作数⼤⼩(字节数)出错.例如:使⽤双字的存储器操作数58Byte register illegal要求⽤字寄存器的指令使⽤了字节寄存器.如PUSH,POP指令的操作数寄存器必须是字寄存器59Illegal uer of CS register指令中错误使⽤了段寄存器CS.如:"MOV CS,AX"CS不能做⽬的操作数60Must be accumulator register要求⽤AX或AL的位置上使⽤可其他寄存器.如IN,OUT指令必须使⽤累加器AX或AL不允许使⽤段寄存器的位置上使⽤了段寄存器.如"SHL DS,1"62Missing or unreachable CS试图跳转去执⾏⼀个CS达不到的标号.通常是指缺少ASSUME语句中CS与代码段相关联63Operand combination illegal双操作数指令中两个操作数组合出错64Near JMP/CALL to different CS试图⽤NEAR属性的转移指令跳转到不在当前段的⼀个地址65Label cannot have segment override段前缀使⽤出错66Must have instuction agter prefix在重复前缀REP,REPE,REPNE后⾯必须有指令67Cannot override ES for destination串操作指令中⽬的操作数不能⽤其他段寄存器替代ES68Cannot address with srgment register指令中寻找⼀个操作数,但ASSUME语句中未指明哪个段寄存器与该操作数所在段有关联69Must be in segment block指令语句没有在段内70Cannot use EVEN or ALIGN with byte alignment在段定义伪指令的定位类型中选⽤BYTE,这时不能使⽤EVEN或ALIGN伪指令71Forward needs override or FAR转移指令的⽬标没有在源程序中说明为FAR属性,可⽤PTR指定72Illegal value for DUP count操作符DUP前的重复次数是⾮法的或未定义73Symbol id already external在模块内试图定义的符号,它已在外部符号伪指令中说明DUP nesting too deep操作数DUP的嵌套太深75Illegak use of undefinde operand( )不定操作符" "使⽤不当.例如"DB 10H DUP( 2)"76Too many valer for struc or record initialization在定义结构变量或记录变量时,初始值太多77Angle brackets requored around initialized list定义结构体变量时,初始值未⽤尖括号()括起来78Directive illegal structure在结构体定义中的伪指令使⽤不当.结构定义中的伪指令语句仅⼆种:分号(;)开始的注释语句和⽤DB,DW等数据定义伪指令语句79Override with DUP illegal在结构变量初始值表中使⽤DUP操作符出错80Field cannot be overridden在定义结构变量语句中试图对⼀个不允许修改的字段设置初值81Override id of wrong type在定义结构变量语句中设置初值时类型出错82Circular chain of EQU aliases⽤等值语句定义的符号名,最后⼜返回指向它⾃⼰.如:A EQU BB EQU A83Cannot emulate cooprocessor opcode 仿真器不能⽀持的8087协处理器操作码84End of file,not END directive 源程序⽂件⽆END⽂件85Data emitted with no segment 语句数据没有在段内86 can't open ml.err把下⾯的复制到⼀个⽂档,命名为ml.err添加到⼯程⽬录FATALcannot open fileI/O error closing fileI/O error reading fileout of memoryassembler limit : macro parameter name table fullinvalid command-line optionnesting level too deepunmatched macro nestingline too longunmatched block nestingdirective must be in control blockerror count exceeds 100; stopping assemblyinvalid numerical command-line argumenttoo many argumentsstatement too complexInternal Assembler Errormissing source filenameCOFF error writing fileinvalid debug and browser data; file exceeds line limitcannot find link.execannot find cvpack.exeSEVEREmemory operand not allowed in contextimmediate operand not allowedcannot have more than one ELSE clause per IF blockextra characters after statementsymbol type conflictsymbol redefinitionundefined symbolnon-benign record redefinitionsyntax errorsyntax error in expressioninvalid type expressiondistance invalid for word size of current segmentPROC, MACRO, or macro repeat directive must precede LOCAL .MODEL must precede this directivecannot define as public or externalsegment attributes cannot changeexpression expectedoperator expectedinvalid use of external symboloperand must be RECORD type or fieldidentifier not a recordrecord constants may not span line breaksinstruction operands must be the same sizeinstruction operand must have sizeinvalid operand size for instructionoperands must be in same segmentconstant expectedoperand must be a memory expressionexpression must be a code addressmultiple base registers not allowedmultiple index registers not allowedmust be index or base registerinvalid use of registerinvalid INVOKE argumentmust be in segment blockDUP too complextoo many initial values for structurestatement not allowed inside structure definitionmissing operand for macro operatorline too longsegment register not allowed in contextstring or text literal too longstatement too complexidentifier too longinvalid character in filemissing angle bracket or brace in literalmissing single or double quotation mark in stringempty (null) stringnondigit in numbersyntax error in floating-point constantreal or BCD number not allowedtext item requiredforced errorforced error : value equal to 0forced error : value not equal to 0forced error : symbol not definedforced error : symbol definedforced error : string blankforced error : string not blankforced error : strings equalforced error : strings not equal[ELSE]IF2/.ERR2 not allowed : single-pass assemblerstructure alignment must be 1, 2, 4, 8, or 16expectedincompatible CPU mode and segment sizeLOCK must be followed by a memory operation instruction prefix not allowedno operands allowed for this instructioninvalid instruction operandsinitializer magnitude too large for specified sizecannot access symbol in given segment or group operands have different framescannot access label through segment registersjump destination too farjump destination must specify a labelinstruction does not allow NEAR indirect addressing instruction does not allow FAR indirect addressing instruction does not allow FAR direct addressingjump distance not possible in current CPU modemissing operand after unary operatorcannot mix 16- and 32-bit registersinvalid scale valueconstant value too largeinstruction or register not accepted in current CPU mode reserved word expectedinstruction form requires 80386/486END directive required at end of filetoo many bits in RECORDpositive value expectedindex value past end of stringcount must be positive or zerocount value too largeoperand must be relocatableconstant or relocatable label expectedsegment, group, or segment register expectedsegment expectedinvalid operand for OFFSETinvalid use of external absolutesegment or group not allowedcannot add two relocatable labelscannot add memory expression and code labelsegment exceeds 64K limitinvalid type for a data declarationHIGH and LOW require immediate operandsN/Acannot have implicit far jump or call to near labeluse of register assumed to ERRORonly white space or comment can follow backslash COMMENT delimiter expectedconflicting parameter definitionPROC and prototype calling conventions conflictinvalid radix tagINVOKE argument type mismatch : argumentinvalid coprocessor registerinstructions and initialized data not allowed in AT segments /AT switch requires the TINY memory modelcannot have segment address references with TINY model language type must be specifiedPROLOGUE must be macro functionEPILOGUE must be macro procedurealternate identifier not allowed with EXTERNDEFtext macro nesting level too deepN/Amissing macro argumentEXITM used inconsistentlymacro function argument list too longN/AVARARG parameter must be last parameterVARARG parameter not allowed with LOCALVARARG parameter requires C calling conventionORG needs a constant or local offsetregister value overwritten by INVOKEstructure too large to pass with INVOKE : argumentnot overriding private proc as publictoo many arguments to INVOKEtoo few arguments to INVOKEinvalid data initializerN/ARET operand too largetoo many operands to instructioncannot have more than one .ELSE clause per .IF block expected data labelcannot nest proceduresEXPORT must be FARinvalid symbol type in expressionbyte register cannot be first operandword register cannot be first operandspecial register cannot be first operandcoprocessor register cannot be first operandcannot change size of expression computationssyntax error in control-flow directivecannot use 16-bit register with a 32-bit addressconstant value out of rangemissing right parenthesistype is wrong size for registerstructure cannot be instancednon-benign structure redefinition: label incorrectnon-benign structure redefinition: too few labels OLDSTRUCTS/NOOLDSTRUCTS state cannot be changed non-benign structure redefinition: incorrect initializersnon-benign structure redefinition: too few initializersnon-benign structure redefinition: label has incorrect offset structure field expectedunexpected literal found in expressionN/Adivide by zero in expressiondirective must appear inside a macrocannot expand macro functiontoo few bits in RECORDmacro function cannot redefine itselfN/Ainvalid qualified typefloating-point initializer on an integer variablenested structure improperly initializedinvalid use of FLATstructure improperly initializedimproper list initializationinitializer must be a string or single iteminitializer must be a single iteminitializer must be a single byteimproper use of list initializerimproper literal initializationextra characters in literal initializationmust use floating-point initializercannot use .EXIT for OS_OS2 with .8086invalid combination with segment alignmentINVOKE requires prototype for procedurecannot include structure in selfsymbol language attribute conflictnon-benign COMM redefinitionCOMM variable exceeds 64Kparameter or local cannot have void typecannot use TINY model with OS_OS2expression size must be 32 bits.EXIT does not work with 32-bit segments.STARTUP does not work with 32-bit segmentsORG directive not allowed in unionsD/Tillegal use of segment registercannot declare scoped code label as PUBLIC.MSFLOAT directive is obsolete : .MSFLOAT ignored ESC instruction is obsolete : ESC ignoredmissing operator in expressionmissing right parenthesis in expressionmissing left parenthesis in expressionreference to forward macro definition16 bit segments not allowed with /coff optionFAR not allowed in flat model comm variablesinvalid .model parameter for flat modelALIAS name is emptyGROUP directive not allowed with /coff option.FPO is not compatible with nested proceduresLEVEL 1cannot modify READONLY segmentN/Anon-unique STRUCT/UNION field used without qualification start address on END directive ignored with .STARTUP cannot ASSUME CSunknown default prologue argumenttoo many arguments in macro calloption untranslated, directive requiredinvalid command-line option value, default is used insufficent memory for /EP : /EP ignoredexpected '>' on text literalmultiple .MODEL directives found : .MODEL ignoredline number information for segment without class 'CODE'directive ignored with /coff switch/Gc switch incompatible with flat model/AT switch incompatible with flat modelinvalid command-line optiondirective ignored without /coff switchdirective ignored outside a procedureLOADDS ignored in flat modeldebug information too complex forwith /coff switch, leading underscore required for start addressLEVEL 2@@: label defined but not referencedexpression expected, assume value 0EXTERNDEF previously assumed to be externallength of symbol previously assumed to be differentsymbol previously assumed to not be in a grouptypes are differentcalling convention not supported in flat modelLEVEL 3N/Ano return from procedureN/Aconditional jump lengthenedprocedure argument or local not referencedexpression may be pass-dependentstructure contains no members87加上.386之后出现乱码应该在.model语句之后加.386使⽤的是 Masm 的话,这⾥有个约定。
C51-keil编译常见错误和警告处理

C51-keil编译常见错误和警告处理53keil错误;C51编译器识别错类型有三种:1、致命错误:伪指令控制行有错,访问不存在的原文;2、语法及语义错误:语法和语义错误都发生在原文件;3、警告:警告出现并不影响目标文件的产生,但执行;C_51FATAL_ERRORACTION:&l;ERROR:<错误信息>termin;FILE:<错误所在文件>;ERROR:<错误信息>keil错误C51编译器识别错类型有三种1、致命错误:伪指令控制行有错,访问不存在的原文件或头文件等。
2、语法及语义错误:语法和语义错误都发生在原文件中。
有这类错误时,给出提示但不产生目标文件,错误超过一定数量才终止编译。
3、警告:警告出现并不影响目标文件的产生,但执行时有可能发生问题。
程序员应斟酌处理。
D.1 致命错误C_51 FATAL_ERROR ACTION: <当前行为> LINE: <错误所在行>ERROR: <错误信息> terminated 或C_51 FATAL ERROR ACTION: <当前行为>FILE: <错误所在文件>ERROR: <错误信息> terminated C_51 TERMINATED C_51 (1) ACTION 的有关信息*PARSING INVOKE-/#PRAGMA_LINE在对#pragma 指明的控制行作此法分析时出错。
*ALLOCATING MEMORY系统分配存储空间时出错。
编译较大程序需要512k空间。
*OPENING INPUT_FILE打开文件时,未找到或打不开源文件/头文件。
*CREATE LIST_FILE/OBJECT_FILE/WORK_FILE不能创建上述文件。
可能磁盘满或文件已存在而且写保护。
*PARSING SOURCE_FILE/ANALYZING DECLARATIONS分析源程序时发现外部引用名太多。
交叉编译几种常见的报错

交叉编译几种常见的报错由于是第一次交叉编译,不知道会出现什么问题,思路就是先把gcc和ld都改成arm的,然后遇到什么问题在解决什么问题,以下过程都是在这个思路下进行。
1.指定arm的编译器和连接器:只是把gcc改为arm-none-linux-gnueabi-gcc,ld改为arm-none-linux-gnueabi-ld,其他的都没有修改。
出现以下错误:arm-none-linux-gnueabi-ld: warning: library search path "/usr/local/lib" is unsafe forcross-compilationarm-none-linux-gnueabi-ld: skipping incompatible /usr/local/lib/libfreetype.so when searchingfor -lfreetypearm-none-linux-gnueabi-ld: skipping incompatible /usr/local/lib/libfreetype.a when searchingfor -lfreetypearm-none-linux-gnueabi-ld: cannot find -lfreetype分析原因是:链接的这些库文件都是在PC编译器下编译出来的,现在把它们和用arm-none-linux-gnueabi-gcc编译出来的文件做链接,当然会出错。
解决方法:这些库重新用arm-gcc重新编译生成相应的库。
下面使用是重新编译库文件的过程:重新编译freetype根据交叉编译的文档,我创建了一个文件夹/usr/local/arm-linux来存放编译后的库文件。
执行:./configure –host=arm-none-linux-gnueabi –prefix=/usr/local/arm-linux注意:host的参数应该是交叉编译环境的前缀。
Cygwin下用crosstool-ng编译交叉工具链

Cygwin下用crosstool-ng 编译交叉工具链Cywin版本:1.7.7(CYGWIN_NT-5.1)Crosstool-ng版本:1.9.3操作系统:Windows XP SP3一、下载crosstool-ngcrosstool-ng的下载地址是:/download/crosstool-ng/值得注意的是,下载里最新的crosstool-ng以后,记得到/download/crosstool-ng/01-fixes/看看有没有相应的补丁,有得话一起下载下来。
本次下载的版本是 1.9.3 无patch。
二、准备crosstool-ng的安装环境使用crosstool-ng必须安装一些开发应用工具:grep,sed,bash,make,gcc,awk,bison,flex,makeinfo,automake,libtool,curl,cvs,patch,gzip,bzip2,liblz ma1,ncurses(对应的库也要装上)三、安装crosstool-ng$ mkdir ~/croosstool-ng# 在当前用户目录下建立croosstool-ng目录$ cd ~/croosstool-ng$ mv /tmp/crosstool-ng-1.9.3.tar.bz2 ./ #把下载的crosstool-ng软件包放到crosstool-ng目录中$ tar -jxvf crosstool-ng-1.9.3.tar.bz2 # 解包$ cd crosstool-ng-1.9.3 # 进入解压目录$ patch -p1 < <补丁文件> # 给crosstool-ng打补丁(如果有)$ ./configure --prefix=/opt/crosstool-ng # 配置crosstool-ng$ make # 编译crosstool-ng$ make install # 安装crosstool-ng$ echo "PA TH=$PATH:/opt/crosstool-ng/bin" >> ~/.bashrc # 为后面调用ct-ng命令增加环境变量$ source ~/.bashrc$ ct-ng helpThis is crosstool-NG version 1.9.3Copyright (C) 2008 Yann E. MORIN <yann.morin.1998@anciens.enib.fr>This is free software; see the source for copying conditions.There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.到此,我们已经成功迈出一大步,好戏还在后头,加油~!四、配置交叉编译工具链$ cd ~/croosstool-ng$ mkdir crosstool-ng-1.9.3_build # 建立一个交叉工具链的输出目录$ mkdir src # 建立保存源码包目录$ mkdir x-tools # 建立交叉编译器的安装路径$ cd crosstool-ng-1.9.3_build/$ cp /opt/crosstool-ng/lib/ct-ng-1.9.3/samples/arm-unknown-linux-gnueabi/crosstool.config .config $ ct-ng menuconfig此时会出现crosstool-ng的配置窗口,针对armv4t体系架构,开始对其进行修改配置:1、已下载好的源码包路径和交叉编译器的安装路径。
Cygwin下用crosstool-ng编译交叉工具链的常见错误及解决办法

Cygwin下用crosstool-ng编译交叉工具链的常见错误及解决办法Cygwin下用crosstool-ng 编译交叉工具链的常见错误及解决办法2011-02-28 21:221、配置crosstool-ng产生的错误1.1 ncurses headers files were not foundChecking for 'ncurses/ncurses.h'... noChecking for 'ncurses/curses.h'... noChecking for 'ncurses.h'... noChecking for 'curses.h'... noncurses headers files were not found解决方法:安装:ncurses,、libncurses-devel1.2 flex none foundChecking for 'flex'... Noflex: none foundEither you are missing entirely the needed tool,or the version you have is too old.configure: Bailing out...解决方法:安装:flex,flexdll1.3 automake 1.10 or above was not foundChecking for 'automake'... noautomake 1.10 or above was not foundEither you are missing entirely the needed tool,or the version you have is too old.configure: Bailing out...解决方法:安装:automake1.4 libtool 1.5.26 or above was not foundChecking for 'libtool'... nolibtool 1.5.26 or above was not foundEither you are missing entirely the needed tool,or the version you have is too old.You can give the path to this tool using: --with-libtool=PATH configure: Bailing out...解决方法:安装:libtool注:在配置crosstool-NG时,出现的类似“XXX:none found”的错误,都可以是该工具没有安装,把该工具安装上,重新配置即可。
GCC常见错误解析

GCC常见错误解析一、错误类型第一类∶C语法错误错误信息∶文件source.c中第n行有语法错误(syntex errror)。
这种类型的错误,一般都是C语言的语法错误,应该仔细检查源代码文件中第n行及该行之前的程序,有时也需要对该文件所包含的头文件进行检查。
有些情况下,一个很简单的语法错误,gcc会给出一大堆错误,此时要保持清醒的头脑,不要被其吓倒,必要的时候再参考一下C语言的基本教材。
第二类∶头文件错误错误信息∶找不到头文件head.h(Can not find include file head.h)。
这类错误是源代码文件中的包含头文件有问题,可能的原因有头文件名错误、指定的头文件所在目录名错误等,也可能是错误地使用了双引号和尖括号。
第三类∶档案库错误错误信息∶连接程序找不到所需的函数库,例如∶ld: -lm: No such file or directory.这类错误是与目标文件相连接的函数库有错误,可能的原因是函数库名错误、指定的函数库所在目录名称错误等,检查的方法是使用find命令在可能的目录中寻找相应的函数库名,确定档案库及目录的名称并修改程序中及编译选项中的名称。
第四类∶未定义符号错误信息∶有未定义的符号(Undefined symbol)。
这类错误是在连接过程中出现的,可能有两种原因∶一是使用者自己定义的函数或者全局变量所在源代码文件,没有被编译、连接,或者干脆还没有定义,这需要使用者根据实际情况修改源程序,给出全局变量或者函数的定义体;二是未定义的符号是一个标准的库函数,在源程序中使用了该库函数,而连接过程中还没有给定相应的函数库的名称,或者是该档案库的目录名称有问题,这时需要使用档案库维护命令ar检查我们需要的库函数到底位于哪一个函数库中,确定之后,修改gcc 连接选项中的-l和-L项。
排除编译、连接过程中的错误,应该说这只是程序设计中最简单、最基本的一个步骤,可以说只是开了个头。
编译器错误诊断与调试技巧

编译器错误诊断与调试技巧在编程的世界里,错误和问题是不可避免的。
无论是初学者还是经验丰富的开发者,都会遇到编译器报错的情况。
然而,面对这些错误,很多开发者往往感到无从下手,不知道如何进行有效的诊断和调试。
本文将介绍一些编译器错误诊断与调试的技巧,帮助开发者更高效地解决问题。
首先,理解错误信息是关键。
编译器通常会提供错误和警告信息,指出代码中的具体问题。
学会仔细阅读这些信息,是定位问题的第一步。
例如,如果编译器指出某一行代码存在语法错误,那么应该首先检查该行的语法是否正确,以及它与周围代码的关系。
其次,利用搜索引擎和社区的力量。
很多时候,我们遇到的问题别人可能已经遇到过并找到了解决方案。
通过将错误信息复制到搜索引擎中查询,或者在开发者社区如Stack Overflow上提问,往往能够快速找到解决问题的线索。
再者,逐步调试是一种高效的排查方法。
大多数集成开发环境(IDE)提供了强大的调试工具,如断点、单步执行和变量监视等。
通过运行程序并在关键点暂停,可以观察程序的运行状态和变量的值,从而逐步缩小问题范围。
此外,编写测试用例也是非常重要的。
良好的测试用例不仅可以确保代码的质量,还可以作为调试的辅助工具。
当修改代码后发现问题时,可以通过运行测试用例来快速验证是否引入了新的错误。
值得一提的是,重构复杂的函数或模块有时也是必要的。
过于复杂的代码往往难以理解和调试。
适时地对代码进行重构,将其拆分成更小、更易于管理的单元,可以提高代码的可读性,降低出错的概率。
最后,不要忽视代码审查的作用。
让同事或其他开发者审查你的代码,他们可能会从不同的角度发现潜在的问题。
这种协作的方式不仅有助于提升代码质量,还能促进团队内的知识共享。
总之,面对编译器的错误诊断和调试,我们需要耐心和细致的分析。
通过阅读错误信息、利用网络资源、使用调试工具、编写测试用例、代码重构和团队协作等方法,我们可以更高效地定位并解决问题。
随着经验的积累,处理这类问题的能力也会逐渐提高。
gcc编译报错解决方案

Gcc最基本的用法是∶gcc [options] [filenames] 其中options就是编译器所需要的参数,filenames给出相关的文件名称。
-c,只编译,不连接成为可执行文件,编译器只是由输入的.c等源代码文件生成.o为后缀的目标文件,通常用于编译不包含主程序的子程序文件。
-o output_filename,确定输出文件的名称为output_filename,同时这个名称不能和源文件同名。
如果不给出这个选项,gcc就给出预设的可执行文件a.out。
1.linker input file unused because linking not done我在Windows下使用SQLite编了个C++程序,在编写Makefile并使用cygwin 中的g++进行编译链接时遇到如下的错误:linker input file unused because linking not done我的语句是g++ -c a.cpp -lsqlite3到网上查了一下,问题出在链接数据库的语句不应出现在编译语句里面。
上面的语句里面有-c 即编译compile,所以命令会忽略掉所有的-l 链接库的命令。
而要链接数据库,应该在生成可执行文件时才使用。
正确的使用链接的语句应该是g++ a.o -L. -lsqlite3 -o exename2.Linux系统的头文件和库文件搜索路径**#include**的头文件,连结数据库,系统定义,总共有下列来源指定gcc去那找。
∙当初在编译时指定的(在~gcc/gcc/collect2.c:locatelib()∙写在specs内的(针对rpm包)∙后来用-D -I -L指定的∙gcc环境变量设定(编译的时候)∙ld.so的环境变量(这是run time的时候)头文件gcc 在编译时如何去寻找所需要的头文件:∙header file的搜寻会从-I开始∙然后找gcc的环境变量C_INCLUDE_PA TH,CPLUS_INCLUDE_PATH,OBJC_INCLUDE_PA TH∙再找内定目录:o/usr/includeo/usr/local/includeo/usr/lib/gcc-lib/i386-linux/2.95.2/includeo/usr/lib/gcc-lib/i386-linux/2.95.2/../../../../include/g++-3o/usr/lib/gcc-lib/i386-linux/2.95.2/../../../../i386-linux/include∙库文件但是如果装gcc的时候,是有给定的prefix的话,那么就是o/usr/includeo prefix/includeo prefix/xxx-xxx-xxx-gnulibc/includeo prefix/lib/gcc-lib/xxxx-xxx-xxx-gnulibc/2.8.1/include库文件cos()等函式库的选项要多加-lm∙编译的时候:gcc会去找-L∙再找gcc的环境变量LIBRARY_PATH∙再找内定目录/lib /usr/lib /usr/local/lib 这是当初compile gcc时写在程序内的运行时动态库的搜索路径1 在配置文件/etc/ld.so.conf中指定动态库搜索路径2 通过环境变量LD_LIBRARY_PA TH指定动态库搜索路径(当通过该环境变量指定多个动态库搜索路径时,路径之间用冒号":"分隔)3 在编译目标代码时指定该程序的动态库搜索路径(还可以在编译目标代码时指定程序的动态库搜索路径。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Cygwin下用crosstool-ng 编译交叉工具链的常见错误及解决办法2011-02-28 21:221、配置crosstool-ng产生的错误1.1 ncurses headers files were not foundChecking for 'ncurses/ncurses.h'... noChecking for 'ncurses/curses.h'... noChecking for 'ncurses.h'... noChecking for 'curses.h'... noncurses headers files were not found解决方法:安装:ncurses,、libncurses-devel1.2 flex none foundChecking for 'flex'... Noflex: none foundEither you are missing entirely the needed tool,or the version you have is too old.configure: Bailing out...解决方法:安装:flex,flexdll1.3 automake 1.10 or above was not foundChecking for 'automake'... noautomake 1.10 or above was not foundEither you are missing entirely the needed tool,or the version you have is too old.configure: Bailing out...解决方法:安装:automake1.4 libtool 1.5.26 or above was not foundChecking for 'libtool'... nolibtool 1.5.26 or above was not foundEither you are missing entirely the needed tool,or the version you have is too old.You can give the path to this tool using: --with-libtool=PATHconfigure: Bailing out...解决方法:安装:libtool注:在配置crosstool-NG时,出现的类似“XXX:none found”的错误,都可以是该工具没有安装,把该工具安装上,重新配置即可。
1.5 ct-ng help命令检查时出错crosstool-ng 安装成功后,用ct-ng help命令检查时,不认识该命令这多半是添加环境变量失败造成的,这时可以打开/home/Administrator目录下的.bashrc查看是否把windows里的其他环境变量添加到了.bashrc文件中,如果把多余的去掉,只保留cgywin自己的环境变量,如下所示:PATH=/usr/local/bin:/usr/bin:/bin:/opt/crosstool-ng-1.9.3/bin1.6 配置时的其他错误在配置crosstool-NG时,也即执行./configure --prefix=/opt/crosstool-ng出现的类似“XXX:none found”的错误,都是相应工具没有安装造成的,重新运行setup.exe把该工具安装上,再执行该命令,即可。
2、编译交叉工具链产生的错误2.1 targets' is *not* case-sensitiveCygwin窗口的错误信息:$ ct-ng build[INFO ] Performing some trivial sanity checks[ERROR] Your file system in'/home/Administrator/croosstool-ng/crosstool-ng-1.9.3/targets' is*not* case-sensitive![00:02] / make: *** [build] Error 1unix 和Linux都是区分大小写的,cygwin既然是模拟unix环境,当然也是区分大小定的。
这个问题好解决,修改一下注册表就行了。
打开注册表,找到如下位置:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager\Kernel把“obcaseinsensitive”的值改为0,再重新启动电脑,cygwin下就区分大小写了。
如果觉得麻烦,可以把如下代码复制到记事本里(case-sensitive.txt):Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager\kernel]"obcaseinsensitive"=dword:00000000然后把记事本的后缀名改为.reg,(case-sensitive.reg),双击reg(case-sensitive.reg)文件即可,和上面的效果一样。
2.1 Installing static core C compiler failedCygwin窗口的错误信息:[INFO ] Installing static core C compiler[EXTRA] Configuring static core C compiler[ERROR] checking for C compiler default output file name... configure: error: C compiler cannot create executablesconf.tab.o[ERROR] Build failed in step 'Installing static core C compiler'[ERROR] Error happened in'/opt/crosstool-ng/lib/ct-ng-1.9.1/scripts/functions' in function'CT_DoExecLog' (line unknown, sorry)x.o[ERROR] called from'/opt/crosstool-ng/lib/ct-ng-1.9.1/scripts/build/cc/gcc.sh' at line # 203 in function 'do_cc_core'il.o[ERROR] called from'/opt/crosstool-ng/lib/ct-ng-1.9.1/scripts/build/cc/gcc.sh' at line # 52 in function 'do_cc_core_pass_1'[ERROR] called from'/opt/crosstool-ng/lib/ct-ng-1.9.1/scripts/crosstool-NG.sh' at line # 597 in function 'main'[ERROR] Look at'/home/Administrator/crosstool-ng/x-tools/arm-apollo-linux-gnueabi/bu ild.log' for more info on this error.解决办法:安装gcc4-g++,在编译的时候时需要C++的参考:/robin_l/blog/item/3087ffa1875a2d83471064bf.html2.2 Build failed in step 'Installing D.U.M.A.'Cygwin窗口的错误信息:[INFO ] Installing D.U.M.A.[EXTRA] Copying sources[ERROR] Build failed in step 'Installing D.U.M.A.'[ERROR]Error happened in'/opt/crosstool-ng-1.9.3/lib/ct-ng-1.9.3/scripts/build/debug/200-duma .sh' in function 'do_debug_duma_build' (line unknown, sorry)[ERROR] called from'/opt/crosstool-ng-1.9.3/lib/ct-ng-1.9.3/scripts/build/debug.sh' atline # 35 in function 'do_debug'[ERROR] called from'/opt/crosstool-ng-1.9.3/lib/ct-ng-1.9.3/scripts/crosstool-NG.sh' at line # 597 in function 'main'[ERROR] Look at'/home/Administrator/ct-ng-1.9.3/crosstool-ng/x-tools/arm-apollo-linu x-gnueabi/build.log' for more info on this error.[ERROR] (elapsed: 479:03.42)[479:07] / make: *** [build] Error 1Build.log中的提示如下:[INFO ] Installing D.U.M.A.[EXTRA] Copying sources[ERROR] Build failed in step 'Installing D.U.M.A.'[ERROR] Error happened in'/opt/crosstool-ng-1.9.3/lib/ct-ng-1.9.3/scripts/build/debug/200-duma.sh' in function 'do_debug_duma_build' (line unknown, sorry)[ERROR] called from'/opt/crosstool-ng-1.9.3/lib/ct-ng-1.9.3/scripts/build/debug.sh' atline # 35 in function 'do_debug'[ERROR] called from'/opt/crosstool-ng-1.9.3/lib/ct-ng-1.9.3/scripts/crosstool-NG.sh' at line # 597 in function 'main'[ERROR] Look at '/home/Administrator/ct-ng-1.9.3/crosstool-ng/x-tools/arm-apollo-linux-gnueabi/build.log' for more info on this error.[ERROR] (elapsed: 479:03.42)解决方法:修改DUMA的Makefile文件:$ tar -zxvf duma_2_5_15.tar.gz #解压源码包$ cd duma_2_5_15打开“GNUmakefile”,添加对cygwin的支持,也就是添加下面红色的一句# some defaults:CC=gccCXX=g++AR=arRANLIB=ranlibINSTALL=installRM=rmRMFORCE=rm -fECHO=echoECHOLF=echoOS=cygwin接下来重新把duma_2_5_15打包$ cd ..$ tar -zcvf duma_2_5_15.tar.gz duma_2_5_15 #重新压缩源码这个错误让我郁闷了几天,因为在build.log文件里的信息也没说出问题可能出在什么地方。