GCC不工作,但G++;做

GCC不工作,但G++;做,c,gcc,debian,C,Gcc,Debian,我试图在“开箱即用”操作系统上的BeagleBone Black上运行一些程序,但在使用gcc编译时,我一直遇到问题。在尝试编译一个简单的hello world程序时,这一点得到了最好的说明: #include <stdio.h> int main(void) { printf("Hello World\n"); return 0; } 我的gcc和g++版本是: debian@beaglebone:~$ gcc --version gcc (Debian 4.7.2-5)

我试图在“开箱即用”操作系统上的BeagleBone Black上运行一些程序,但在使用gcc编译时,我一直遇到问题。在尝试编译一个简单的hello world程序时,这一点得到了最好的说明:

#include <stdio.h>

int main(void)
{
 printf("Hello World\n");
 return 0;
}
我的gcc和g++版本是:

debian@beaglebone:~$ gcc --version
gcc (Debian 4.7.2-5) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

debian@beaglebone:~$ g++ --version
g++ (Debian 4.7.2-5) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
以前有人遇到过这个问题吗?我环顾了一下四周,但没有一个修复方案是适用的。提前谢谢

编辑:gcc-v helloworld.c-o输出文件的输出

debian@beaglebone:~$ gcc -v helloworld.c -o outputFile
Using built-in specs.
COLLECT_GCC=gcc
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-5' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libitm --enable-plugin --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-5)
COLLECT_GCC_OPTIONS='-E' '-v' '-o' 'outputFile' '-march=armv7-a' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mthumb' '-mtls-dialect=gnu'
 /usr/lib/gcc/arm-linux-gnueabihf/4.7/cc1 -E -quiet -v -imultilib . -imultiarch arm-linux-gnueabihf helloworld.c -o outputFile -march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16 -mthumb -mtls-dialect=gnu
ignoring nonexistent directory "/usr/local/include/arm-linux-gnueabihf"
ignoring nonexistent directory "/usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../../arm-linux-gnueabihf/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/arm-linux-gnueabihf/4.7/include
 /usr/local/include
 /usr/lib/gcc/arm-linux-gnueabihf/4.7/include-fixed
 /usr/include/arm-linux-gnueabihf
 /usr/include
End of search list.
COMPILER_PATH=/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib/gcc/arm-linux-gnueabihf/:/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib/gcc/arm-linux-gnueabihf/
LIBRARY_PATH=/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../arm-linux-gnueabihf/:/usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../:/lib/arm-linux-gnueabihf/:/lib/:/usr/lib/arm-linux-gnueabihf/:/usr/lib/
COLLECT_GCC_OPTIONS='-E' '-v' '-o' 'outputFile' '-march=armv7-a' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mthumb' '-mtls-dialect=gnu'
debian@beaglebone:~$gcc-v helloworld.c-o输出文件
使用内置规格。
收集\u GCC=GCC
目标:arm linux gnueabihf
配置为:../src/configure-v——使用pkgversion='Debian 4.7.2-5'——使用bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs -启用语言= C、C++、GO、FORTRAN、Objc,obj-c++--prefix=/usr--program suffix=-4.7--enable shared--enable linker build id--with system zlib--libexecdir=/usr/lib--withinclude gettext--enable threads=posix--with gxx include dir=/usr/include/c++/4.7--libdir/usr/lib enable nls--with sysroot=/--enable clocale=gnu--enable libstdcxx debug--enable libstdcxx debug--enable libstdcxx time=--启用gnu唯一对象--禁用libitm--启用插件--启用objc gc--禁用sjlj异常--使用arch=armv7-a--使用fpu=vfpv3-d16--使用float=hard--使用mode=thumb--启用检查=发布--build=arm linux gnueabihf--host=arm linux gnueabihf--target=arm linux gnueabihf
线程模型:posix
gcc版本4.7.2(Debian 4.7.2-5)
COLLECT_GCC_OPTIONS='-E'-v'-o''输出文件''-march=armv7-a'-mfloat abi=hard'-mfpu=vfpv3-d16'-mthumb'-mtls方言=gnu'
/usr/lib/gcc/armlinux-gnueabihf/4.7/cc1-E-quiet-v-imultilib-imultimarch arm linux gnueabihf helloworld.c-o outputFile-march=armv7-a-mfloat abi=hard-mfpu=vfpv3-d16-mthumb-mtls方言=gnu
忽略不存在的目录“/usr/local/include/arm-linux-gnueabihf”
忽略不存在的目录“/usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../../../../../arm-linux-gnueabihf/include”
#包括“…”搜索从这里开始:
#包括搜索从这里开始:
/usr/lib/gcc/arm-linux-gnueabihf/4.7/include
/usr/本地/包括
/usr/lib/gcc/arm-linux-gnueabihf/4.7/include-fixed
/usr/include/arm-linux-gnueabihf
/usr/包括
搜索列表结束。
编译器_PATH=/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib/gcc/arm-linux-gnueabihf/:/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib gcc/arm linux-gnueabihf/
LIBRARY_PATH=/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../../../arm-linux-gnueabihf/:/usr/lib/arm-linux-gnueabihf/:/usr/lib arm-linux-gnueabihf/:/usr/lib/
COLLECT_GCC_OPTIONS='-E'-v'-o''输出文件''-march=armv7-a'-mfloat abi=hard'-mfpu=vfpv3-d16'-mthumb'-mtls方言=gnu'

在详细的编译器输出中显示秘密:

COLLECT_GCC_OPTIONS='-E'[…]

-E激发GCC只对输入进行预处理,因此生成的“test”文件实际上是解析了单个include的输入文件(递归)


由于没有显式地添加-E参数,gcc显然隐式地添加了-E参数。根据gcc.gnu.org上的讨论,您的gcc版本似乎已经编译好了,所以我假设您必须从固定源代码重新编译gcc,或者从任何源代码(Debian存储库?)获得正确编译的gcc版本。

您可以尝试使用
\gcc
而不是
gcc
。前导的反斜杠告诉shell忽略可能对同名可执行文件产生阴影的任何别名。您还可以使用完整的gcc路径来实现相同的功能


您还可以使用
类型gcc
,检查是否存在名为gcc的别名或函数,
什么是gcc
或者可能
哪个gcc
或者甚至使用较低级别的
集| grep gcc

尝试调用可执行文件而不是
测试
你确定没有意外地在gcc选项中加入
-E
,当您运行
gcc
时,文件
/test
中的结果是预处理的源代码,就像您在命令行上提供了
-E
选项一样。这不是
gcc
的正常行为,这些评论的目的是为了寻找一些可能的原因,解释为什么在没有明确指定
-E
的情况下可能会出现这种行为。既然那不是淘金,你应该考虑对BeagleBone的支持论坛进行查询。输出的代码> GCC -V HeloOLLD.C-O测试确实包括:<代码> GCCDYOPTIONS=-E′-V′-O′测试'Max= ARMV7A′-MFLAP ABI=HART '-MFPU= VFPV3-D16′-MMPON' -MTLS方言=GNU '/COMPUT>这确实提示-E可能是问题所在。它链接到预处理器。这就是
-E
的基本意思-转储预处理的输出。从这里开始,我认为Stackoverflow的工作已经完成了。你必须自己弄清楚为什么你的安装是以如此奇怪的方式设置的。欢迎来到Stack Overflow。如果您仔细查看这些注释,您会发现问题已经解决了—在堆栈溢出可以解决的范围内—通过推断命令行中有一个杂散的
-E
。虽然我同意如果有一个包含
-E
gcc
别名,那么您的技术可以避免这个问题,但评论中有证据表明,这个问题比这个问题更根本。
debian@beaglebone:~$ gcc -v helloworld.c -o outputFile
Using built-in specs.
COLLECT_GCC=gcc
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-5' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libitm --enable-plugin --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-5)
COLLECT_GCC_OPTIONS='-E' '-v' '-o' 'outputFile' '-march=armv7-a' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mthumb' '-mtls-dialect=gnu'
 /usr/lib/gcc/arm-linux-gnueabihf/4.7/cc1 -E -quiet -v -imultilib . -imultiarch arm-linux-gnueabihf helloworld.c -o outputFile -march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16 -mthumb -mtls-dialect=gnu
ignoring nonexistent directory "/usr/local/include/arm-linux-gnueabihf"
ignoring nonexistent directory "/usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../../arm-linux-gnueabihf/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/arm-linux-gnueabihf/4.7/include
 /usr/local/include
 /usr/lib/gcc/arm-linux-gnueabihf/4.7/include-fixed
 /usr/include/arm-linux-gnueabihf
 /usr/include
End of search list.
COMPILER_PATH=/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib/gcc/arm-linux-gnueabihf/:/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib/gcc/arm-linux-gnueabihf/
LIBRARY_PATH=/usr/lib/gcc/arm-linux-gnueabihf/4.7/:/usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../arm-linux-gnueabihf/:/usr/lib/gcc/arm-linux-gnueabihf/4.7/../../../:/lib/arm-linux-gnueabihf/:/lib/:/usr/lib/arm-linux-gnueabihf/:/usr/lib/
COLLECT_GCC_OPTIONS='-E' '-v' '-o' 'outputFile' '-march=armv7-a' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mthumb' '-mtls-dialect=gnu'