简体   繁体   English

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

[英]GCC not working but G++ does

I am trying to run some programs on a BeagleBone Black on the 'out of the box' operating system but I keep getting issues when compiling with gcc. 我试图在'开箱即用'的操作系统上运行BeagleBone Black上的一些程序,但是在使用gcc编译时我一直遇到问题。 This is best illustrated when trying to compile a simple hello world program: 在尝试编译简单的hello world程序时,最好地说明了这一点:

#include <stdio.h>

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

The output from compiling and running this is: 编译和运行它的输出是:

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:~$

My gcc and g++ versions are: 我的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.

Has anyone come across this problem before? 有没有人遇到过这个问题? I've had a look around but none of the fixes seem applicable. 我已经浏览了一下,但没有一个修复程序似乎适用。 Thanks in Advance. 提前致谢。

edit: output of gcc -v helloworld.c -o outputFile 编辑:输出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'

The secret is revealed in the verbose compiler output: 这个秘密在详细的编译器输出中显示出来:

COLLECT_GCC_OPTIONS='-E' [...] COLLECT_GCC_OPTIONS =' - E'[...]

-E provokes GCC just to preprocess the input, so the resulting 'test' file actually is the input file with the single include resolved (recursively). -E激发GCC只是为了预处理输入,因此生成的'test'文件实际上是输入文件,其中包含单个include(递归)。

Since you did not add the -E parameter explicitely, gcc obviously did so implicitely. 由于你没有明确地添加-E参数,所以gcc显然是这样做的。 According to this discussion on gcc.gnu.org, your version of gcc seems to have this compiled in, so I assume you would have to recompile gcc from fixed source code - or get a properly compiled gcc version from whichever source (Debian repositories?). 根据gcc.gnu.org上的这个讨论,你的gcc版本似乎已经编译好了,所以我假设你必须从固定源代码重新编译gcc - 或从任何来源(Debian存储库?)获得正确编译的gcc版本? )。

You can try to use \\gcc instead of gcc . 您可以尝试使用\\gcc而不是gcc The leading backslash tells the shell to ignore any aliases which might shadow the executable of the same name. 前导反斜杠告诉shell忽略任何可能影响同名可执行文件的别名。 You can also use the full gcc path to achieve the same. 您还可以使用完整的gcc路径来实现相同的目标。

You can also check there is no aliases or functions named gcc using type gcc , whatis gcc or maybe which gcc or even using a lower level set|grep gcc . 您还可以使用type gccwhatis gcc或者which gcc或甚至使用较低级别的set|grep gcc来检查没有名为gcc的别名或函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM