GCC 4.9.2问题 - 链接错误“开始”符号未定义(优胜美地更新后)

时间:2014-11-28 06:01:30

标签: gcc homebrew osx-yosemite

所以,我升级到优胜美地,并将gcc更新为gcc-4.9。现在什么都不行。即使是像这样的基本C程序:

#include "stdio.h"

void main() {
    printf("woh!");
}

gcc -v a.c的详情如下。基本错误是:

Undefined symbols for architecture x86_64:
  "start", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

这是我对CC,clang和gcc的配置。

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/4.9.2/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/lto-wrapper
Target: x86_64-apple-darwin14.0.0
Configured with: ../configure --build=x86_64-apple-darwin14.0.0 --prefix=/usr/local/Cellar/gcc/4.9.2 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-4.9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-cloog=/usr/local/opt/cloog --with-isl=/usr/local/opt/isl --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --disable-werror --with-pkgversion='Homebrew gcc 4.9.2' --with-bugurl=https://github.com/Homebrew/homebrew/issues --enable-plugin --disable-nls --enable-multilib
Thread model: posix
gcc version 4.9.2 (Homebrew gcc 4.9.2) 

我已经使用Homebrew成功安装了gcc到gcc-4.9的链接。我已经运行brew doctor并且没有收到任何问题。使用code-select -install

更新了命令行工具
Gautams-MacBook-Pro:~ gautamrege$ ls -l /usr/local/bin/gcc
lrwxrwxr-x  1 gautamrege  admin  22 Nov 14 20:14 /usr/local/bin/gcc@ -> /usr/local/bin/gcc-4.9
Gautams-MacBook-Pro:~ gautamrege$ ls -l /usr/local/bin/gcc-4.9 
lrwxrwxr-x  1 gautamrege  admin  31 Nov 14 20:14 /usr/local/bin/gcc-4.9@ -> ../Cellar/gcc/4.9.2/bin/gcc-4.9

这些是我的CC和clang版本(基本相同)

Gautams-MacBook-Pro:~ gautamrege$ CC -v
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
Gautams-MacBook-Pro:~ gautamrege$ clang -c
clang: error: no input files
Gautams-MacBook-Pro:~ gautamrege$ clang -v
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix

最后,这是使用gcc -v的详细日志。

$ gcc -v a.c
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/4.9.2/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/lto-wrapper
Target: x86_64-apple-darwin14.0.0
Configured with: ../configure --build=x86_64-apple-darwin14.0.0 --prefix=/usr/local/Cellar/gcc/4.9.2 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-4.9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-cloog=/usr/local/opt/cloog --with-isl=/usr/local/opt/isl --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --disable-werror --with-pkgversion='Homebrew gcc 4.9.2' --with-bugurl=https://github.com/Homebrew/homebrew/issues --enable-plugin --disable-nls --enable-multilib
Thread model: posix
gcc version 4.9.2 (Homebrew gcc 4.9.2) 
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.10.0' '-v' '-mtune=core2'
 /usr/local/Cellar/gcc/4.9.2/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/cc1 -quiet -v -D__DYNAMIC__ a.c -fPIC -quiet -dumpbase a.c -mmacosx-version-min=10.10.0 -mtune=core2 -auxbase a -version -o /var/folders/dr/kc0cps51533gqx5zm8gv33x80000gn/T//ccvx7Ydq.s
GNU C (Homebrew gcc 4.9.2) version 4.9.2 (x86_64-apple-darwin14.0.0)
    compiled by GNU C version 4.9.2, GMP version 6.0.0, MPFR version 3.1.2-p10, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/Cellar/gcc/4.9.2/include"
ignoring nonexistent directory "/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../x86_64-apple-darwin14.0.0/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/include
 /usr/local/include
 /usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/include-fixed
 /usr/include
 /System/Library/Frameworks
 /Library/Frameworks
End of search list.
GNU C (Homebrew gcc 4.9.2) version 4.9.2 (x86_64-apple-darwin14.0.0)
    compiled by GNU C version 4.9.2, GMP version 6.0.0, MPFR version 3.1.2-p10, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: f90e36a64a568856fa161772b1b4076f
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.10.0' '-v' '-mtune=core2'
 as -arch x86_64 -force_cpusubtype_ALL -o /var/folders/dr/kc0cps51533gqx5zm8gv33x80000gn/T//cckdbo1t.o /var/folders/dr/kc0cps51533gqx5zm8gv33x80000gn/T//ccvx7Ydq.s
COMPILER_PATH=/usr/local/Cellar/gcc/4.9.2/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2/libexec/gcc/x86_64-apple-darwin14.0.0/:/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/
LIBRARY_PATH=/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../:/usr/lib/
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.10.0' '-v' '-mtune=core2'
 /usr/local/Cellar/gcc/4.9.2/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/collect2 -dynamic -arch x86_64 -macosx_version_min 10.10.0 -weak_reference_mismatches non-weak -o a.out -L/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2 -L/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../.. /var/folders/dr/kc0cps51533gqx5zm8gv33x80000gn/T//cckdbo1t.o -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem -v
collect2 version 4.9.2
/usr/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.10.0 -weak_reference_mismatches non-weak -o a.out -L/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2 -L/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../.. /var/folders/dr/kc0cps51533gqx5zm8gv33x80000gn/T//cckdbo1t.o -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem -v
@(#)PROGRAM:ld  PROJECT:ld64-136
configured to support archs: armv6 armv7 armv7s i386 x86_64
Library search paths:
    /usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2
    /usr/local/Cellar/gcc/4.9.2/lib
    /usr/lib
    /usr/local/lib
Framework search paths:
    /Library/Frameworks/
    /System/Library/Frameworks/
Undefined symbols for architecture x86_64:
  "start", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

我非常确定我犯了一些基本的错误。无论如何,所有其他软件包安装都因为同样的错误而失败。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

将评论中的信息复制到此社区Wiki答案。

Tim Smith pointed out要解决此问题的关键:

sudo xcode-select -s /Library/Developer/CommandLineTools/

这可确保clang调用clang的XCode 6版本。