簡體   English   中英

GCC沒有工作,但G ++確實如此

[英]GCC not working but G++ does

我試圖在'開箱即用'的操作系統上運行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'

這個秘密在詳細的編譯器輸出中顯示出來:

COLLECT_GCC_OPTIONS =' - E'[...]

-E激發GCC只是為了預處理輸入,因此生成的'test'文件實際上是輸入文件,其中包含單個include(遞歸)。

由於你沒有明確地添加-E參數,所以gcc顯然是這樣做的。 根據gcc.gnu.org上的這個討論,你的gcc版本似乎已經編譯好了,所以我假設你必須從固定源代碼重新編譯gcc - 或從任何來源(Debian存儲庫?)獲得正確編譯的gcc版本? )。

您可以嘗試使用\\gcc而不是gcc 前導反斜杠告訴shell忽略任何可能影響同名可執行文件的別名。 您還可以使用完整的gcc路徑來實現相同的目標。

您還可以使用type gccwhatis gcc或者which gcc或甚至使用較低級別的set|grep gcc來檢查沒有名為gcc的別名或函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM