64"start"

How can I link my program?

I have a mid 2012 macbook pro which I recently upgraded to OSX 10.11 (El Capitan). In order to compile c++ programs I had to reinstall g++ which I did using brew.

Now I am getting an error when trying to link my program.

g++-6 -o hello hello.o

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

Here is my code: hello.cpp

#include <iostream>
int main(){
    std::cout<<"Beginning program";
    return 0;
}

And this is the output when I link with the -v flag

g++-6 -o hello hello.o -v

Using built-in specs.

COLLECT_GCC=g++-6

COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin15.6.0/6.2.0/lto-wrapper

Target: x86_64-apple-darwin15.6.0

Configured with: ../configure --build=x86_64-apple-darwin15.6.0 --prefix=/usr/local/Cellar/gcc/6.2.0 --libdir=/usr/local/Cellar/gcc/6.2.0/lib/gcc/6 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-6 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --with-build-config=bootstrap-debug --disable-werror --with-pkgversion='Homebrew gcc 6.2.0' --with-bugurl=https://github.com/Homebrew/homebrew/issues --enable-plugin --disable-nls --enable-multilib

Thread model: posix

gcc version 6.2.0 (Homebrew gcc 6.2.0)

COMPILER_PATH=/usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin15.6.0/6.2.0/:/usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin15.6.0/6.2.0/:/usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin15.6.0/:/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0/:/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/

LIBRARY_PATH=/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0/:/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0/../../../

COLLECT_GCC_OPTIONS='-o' 'hello' '-v' '-mmacosx-version-min=10.11.3' '-shared-libgcc' '-mtune=core2' /usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin15.6.0/6.2.0/collect2 -dynamic -arch x86_64 -macosx_version_min 10.11.3 -weak_reference_mismatches non-weak -o hello -L/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0 -L/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0/../../.. hello.o -lstdc++ -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem -v collect2 version 6.2.0 /usr/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.11.3 -weak_reference_mismatches non-weak -o hello -L/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0 -L/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0/../../.. hello.o -lstdc++ -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/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0 /usr/local/Cellar/gcc/6.2.0/lib/gcc/6 /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

I've read from other posts that this might be a problem with the default libraries being compiled by an older version of g++. But I think that isn't the problem here because the library search paths seem to point g++ towards g++-6's libraries.

链接地址: http://www.djcxy.com/p/75478.html

上一篇: 无法使用f2py链接大型PETSc / SLEPc Fortran代码

下一篇: 64“开始”