GCC没有工作,但G ++确实如此

时间:2015-12-15 22:30:05

标签: c gcc debian

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

#include <stdio.h>

int main(void)
{
 printf("Hello World\n");
 return 0;
}

编译和运行它的输出是:

debian@beaglebone:~$ g++ helloworld.c -o test
debian@beaglebone:~$ ./test
Hello World
debian@beaglebone:~$ gcc helloworld.c -o test
debian@beaglebone:~$ ./test
./test: line 27: typedef: command not found
./test: line 36: typedef: command not found
./test: line 37: typedef: command not found
./test: line 38: typedef: command not found
./test: line 39: typedef: command not found
./test: line 42: typedef: command not found
./test: line 43: typedef: command not found
./test: line 44: typedef: command not found
./test: line 45: typedef: command not found
./test: line 46: typedef: command not found
./test: line 47: typedef: command not found
./test: line 52: __extension__: command not found
./test: line 53: __extension__: command not found
./test: line 61: __extension__: command not found
./test: line 62: __extension__: command not found
./test: line 68: __extension__: command not found
./test: line 69: __extension__: command not found
./test: line 70: __extension__: command not found
./test: line 71: __extension__: command not found
./test: line 72: __extension__: command not found
./test: line 73: __extension__: command not found
./test: line 74: __extension__: command not found
./test: line 75: __extension__: command not found
./test: line 76: __extension__: command not found
./test: line 77: __extension__: command not found
./test: line 78: syntax error near unexpected token `}'
./test: line 78: `__extension__ typedef struct { int __val[2]; } __fsid_t;'
debian@beaglebone:~$

我的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 outputFile

的输出
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'

2 个答案:

答案 0 :(得分:1)

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

COLLECT_GCC_OPTIONS =' - E'[...]

-E激发GCC只是为了预处理输入,因此生成的'test'文件实际上是输入文件,其中包含单个include(递归)。

由于你没有明确地添加-E参数,所以gcc显然是这样做的。根据{{​​3}}对gcc.gnu.org的讨论,你的gcc版本似乎编译了这个,所以我假设你必须从固定的源代码重新编译gcc - 或从任何来源获得正确编译的gcc版本(Debian存储库?)。

答案 1 :(得分:0)

您可以尝试使用\gcc代替gcc。前导反斜杠告诉shell忽略任何可能影响同名可执行文件的别名。您也可以使用完整的gcc路径来实现相同的目标。

您还可以使用type gccwhatis gccwhich gcc或甚至使用较低级别set|grep gcc来检查没有名为gcc的别名或函数。

相关问题