Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sysProgrammer

macrumors member
Original poster
If anyone has a solution for getting gcc/g++ to work on Maverick please respond.
I searched and tried everything short of installing and compiling gcc from the gcc project pages.

Tried and it complains that the download server is down.
$ xcode-select --install
xcode-select: note: install requested for command line developer tools

Went to developers website, logged in and downloaded xcode command line tools for maverick -that didnt work either.

Still get

Code:
g++ -g -Wall -v test1.cpp -o test1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.9.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name test1.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 224.1 -v -g -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0 -stdlib=libc++ -Wall -fdeprecated-macro -fdebug-compilation-dir /Users/alanahmetspahic/cpp/test -ferror-limit 19 -fmessage-length 112 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/l2/g7dm2byn60b5nfvrt0_851xr0000gn/T/test1-rJj4lZ.o -x c++ test1.cpp
clang -cc1 version 5.0 based upon LLVM 3.3svn default target x86_64-apple-darwin13.0.0
ignoring nonexistent directory "/usr/include/c++/v1"
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.9.0 -o test1 /var/folders/l2/g7dm2byn60b5nfvrt0_851xr0000gn/T/test1-rJj4lZ.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/lib/darwin/libclang_rt.osx.a
ld: can't write output file: test1 for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
 
Last edited by a moderator:
Download and install Xcode. In the preferences pane is an option to install the command line tools. I don't know if that's different than the way you tried. But it seems to be the official interface.
 
Download and install Xcode. In the preferences pane is an option to install the command line tools. I don't know if that's different than the way you tried. But it seems to be the official interface.

That would be the case for Mountain Lion, but in Mavericks that is GONE.
So the workaround described on the web is to go ahead log into developers portal and download Command Line Tools for Mavericks.

BUT WAIT.
It is not the same as the one for ML since it doesn't have g++/gcc support

BUT WAIT.
You can't install g++/gcc support from brew since you can't install brew

BUT WAIT.
if you do xcode-select --install it starts the install but fails complaining update server is down.


All is already posted here:
http://crosstown.coolestguidesontheplanet.com/os-x/55-setting-up-os-x-mavericks-and-homebrew

I am debating going to ML but this is brand new laptop, so that would be a challenge.
 
That would be the case for Mountain Lion, but in Mavericks that is GONE.
So the workaround described on the web is to go ahead log into developers portal and download Command Line Tools for Mavericks.

When I first started the Xcode.app after installing it a dialog popup up wanting to install additional items I said yes and it installed the command line tools, which contains gcc.

Code:
MacUser2525:~$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
 
The tools exist and are being used. The evidence of this is the posted log output. It even says which version of the tools are used:
Code:
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)


The specific problem is this:
Code:
ld: can't write output file: test1 for architecture x86_64

The linker command that led to this problem is this:
Code:
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.9.0 -o test1 /var/folders/l2/g7dm2byn60b5nfvrt0_851xr0000gn/T/test1-rJj4lZ.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/lib/darwin/libclang_rt.osx.a
The first thing that comes to mind for being unable to write an output file is an existing directory with that name. Or possibly inadequate permissions to write to the current directory.

The second thing that comes to mind is that one or more libraries being linked to doesn't supply an x86_64 version of linkable code.


If neither of those two reasons can be confirmed, I suggest making a simplified test case: the C++ hello-world example. Compile it with the simplest command-line possible, i.e. not specifying an output file, so the executable would normally be a.out. If the simplest test case works, then add command-line options one at a time until it fails, starting with -v for visibility. Post all results (i.e. post the exact command-line used and the log produced) because sometimes the clues lie in how you got there, not the destination.
 
This is on Mavericks, with Xcode version 5.0.1.

Xcode -> Preferences -> Locations:

Command Line Tools: Xcode 5.0.1

Not sure what was there before I installed them. There might have been a pop-up. Or maybe it was originally on the Downloads page. I'm don't remember.

From the terminal:
Code:
rmbp:~/tmp$ cat hello.cpp
#include <iostream>

int main(int argc, char *argv[])
{
	std::cout << "Hello World" << std::endl;
}

rmbp:~/tmp$ g++ -v -o hello hello.cpp
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.9.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name hello.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 224.1 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/rmoore/tmp -ferror-limit 19 -fmessage-length 127 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/9d/99hw_gn97pj1ms_jrgg3454c0000gn/T/hello-BfAGnI.o -x c++ hello.cpp
clang -cc1 version 5.0 based upon LLVM 3.3svn default target x86_64-apple-darwin13.0.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.9.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -o hello /var/folders/9d/99hw_gn97pj1ms_jrgg3454c0000gn/T/hello-BfAGnI.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/lib/darwin/libclang_rt.osx.a

rmbp:~/tmp$ ./hello 
Hello World
 
I found the issue

The issue was upgrade to Mavericks which had libraries from MLion with its configuration of Xcode left. I am not sure how. Clean install resolved all the issues.

Part of the frustration was that neither clang nor g++ nor any of the tools were working due to the library corruption.

Interesting few days I had...
 
Is there any reason why you wouldn't use Clang?

Not in particular, but I am just used to gcc/g++ from many years of development on linux. Clang last time I tried to use it on linux, threw a bunch of errors at standard library which was a bit of a shock.

Anyway in this situation Clang didn't work either. Same problems. I think if you are going to move to Maverick from MTLion, you better do a clean install, otherwise it's going to be a lot of fun trying to chase down all the files/ library paths..

When I reinstalled mavericks, I wrote a simple test app which invoked g++. Upon g++ call the OS recognized the library missing and it downloaded command line tools (even without Xcode being present). Then magically all worked back the way it was supposed to.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.