I've got NetBeans 6.9 installed on a Mac OS Snow Leopard. Also, I installed gcc 4.4 through MacPorts in order to experiment with C++0x. I believe, by default NetBeans uses the standard Apple gcc 4.2 compiler which is invoked through a g++ symlink found in /usr/bin.
My question is: how can I still use the new compiler?
I tried creating a new Tool Collection in NetBeans by specifying the default directory to /opt/local/bin which is where gcc 4.4 is present. But this caused error messages, i.e. No compiler sets were found.... I also tried modifying the existing GNU Tool Collection by selectively specifying the C++ Compiler command as /opt/local/bin/x86_64-apple-darwin10-g++-mp-4.4. However, this caused build errors which I didn't even understand. Any ideas appreciated.
What you describe here, adding a new tools chain with that path, just should work with gcc 4.4, see here http://forums.netbeans.org/post-70004.html
Are you sure nothing is missing in your GCC 4.4 ?
The only missing step is to click "Reset Settings" help in Code Assistance tab after creating the tool chain, to make sure that code assistance picks the new headers.
This works for me:
Create a directory for your toolchain:
mkdir -p ~/toolchains/gcc-4.4-mp/bin
then link gcc's binaries into the bin directory
cd ~/toolchains/gcc-4.4-mp/bin
ln -fs /opt/local/bin/*-mp-4.4
and give gcc's tools their unmodified names back:
for x in *-mp-4.4 ; do ln -fs $x ${x%-mp*} ; done
or
for x in *-mp-4.4 ; do mv $x ${x%-mp*} ; done
Now you can add ~/toolchains/gcc-4.4-mp/bin as a new Toolchain Collection.
Here's the "easiest" solution. Edit your PATH environment variable and then open NetBeans.
sudo port install gcc_select
sudo gcc_select mp-gcc44
# tcsh:
setenv PATH /opt/local/bin:${PATH}
# bash:
PATH=/opt/local/bin:${PATH}; export PATH
# And then:
open /Applications/NetBeans.app
You should be good to go after that unless NetBeans (uses an absolute path to the compiler).
Related
I am not sure if I should delete the X Code as it takes a lot of space on MacBook. I want to use g++ compiler for compiling my c++ program.
It is possible to install just the Xcode command line tools. Open Terminal and execute xcode-select --install. This will get you your compiler (clang, not g++. g++ is just an alias for clang++ on Macs), linker, make, etc.
To actually answer your question, yes. If you install something and then uninstall it, the stuff that got installed will get uninstalled.
If you want the actual g++ compiler, you will need to install it yourself, homebrew is the easiest way. The gcc package will create versioned symlinks for you (g++-9), and you can just use that, or create another symlink that redirects g++ to g++-9. If you did that, you'll have to remember to manually update that symlink when the major version changes. All this is found in usr/local/bin after installing homebrew and the gcc package.
I am running centos 6 on a cluster. I installed the latest gcc-8.2.0. and made a link "ln -sf /usr/bin/gcc-8.2 gcc".
I did the same for g++ and gfortran.
I wanted to reinstall gcc-8.2.0 and went ahead to
make clean
in the gcc-8.2 directory.
When I try
./configure
I get that C compiler cannot create executables
The links I made are broken.
The system gcc-4.4.7 cannot be found
which gcc
gives no gcc
sudo yum install gcc gcc-c++
gives gcc is already installed.
I tried to install an rpm, which fails because of dependencies.
I have pg compilers installed in /opt/pgi
When I configure with
CC=/path to/pgi/bin/pgcc FC=/path to/pgi/bin/pgfortran ./configure
I still get C compiler cannot create executables
I tried the following c++ programm
#include <iostream>
using namespace std;
int main() {
cout << "Hello world!" << endl;
return 0;
}
With the command
/opt/pgi/linux_86_64/12.08/bin/pgcpp hello.cpp -o hello
It gives compilation error that float.h not found. On another linux PC with working gcc, the program works with the command
g++ hello.cpp -o hello
I will appreciate any assistance to either find the systemgcc or use pg compilers to compile gcc if possible
I admit it is a big mess which will require OS reinstallation and reconfiguration. But then I did
sudo yum install compat-gcc-34
Now I have gcc34 and configure of gcc-8.2 goes through without "c compiler cannot create executables". (Note that the ./configure referred to in earlier post was actually
../gcc_8_2_release/configure
inside "gcc_8_2_release_build, so gcc was not being built in its source directory.
The problem I have now is with make, which needs g++, giving error
uint_t(64) or int_t(64) not found.
Thanks all who have gone through this post, for your patience.
Any assistance will be appreciated.
Here is how I got out of this mess.
With the following two commands
sudo yum install compat-gcc-34-c++
sudo yum install compat-gcc-34-g77
I was able to install the older version of gcc, c++ and g77. Then I was able to build gcc-8.2.
Now I have a functional system with the latest gcc, yes it may need re-installation/re-configuring but it is fully functional.
I have learnt a lot and very much appreciate the comments and guidelines of #Basile. However, at one point he was rather negative and discouraging.
But thanks to my belief and perseverance, and more importantly browsing the knowledge shared by others, I have been able to recover what I was beginning to be convinced was a lost cause.
Thanks all.
This is more a sysadmin question than a programming one.
My recommendations:
don't mess your /usr/bin/. Leave your package manager yum to fill it -and never add anything inside it without yum ; so remove manually any symlinks you made there (by mistake)
reinstall the old system gcc 4.4 and g++ 4.4 (using yum)
rebuild your GCC 8 from scratch from its source code. Configure it with --program-suffix=-8 (but no --prefix, or a --prefix=$HOME/soft/ if you don't have root access). So it will install /usr/local/bin/gcc-8 and /usr/local/bin/g++-8 etc... (or, if you have given --prefix=$HOME/soft/ , a $HOME/soft/bin/gcc-8 etc...)
create a $HOME/bin/ if you don't have already one
be sure to have $HOME/bin/ early in your $PATH (before /usr/bin/)
add a symlink ln -sv /usr/local/bin/gcc-8 $HOME/bin/gcc and likewise for g++ etc..
Then, when you type gcc you are getting that symlink to /usr/local/bin/gcc-8 etc.
If you cannot write to /usr/local/ (e.g. because you don't have root permission...) you could pass --prefix=$HOME/soft/ to GCC 8 .../configure then replace /usr/local/ above with $HOME/soft/
If you are the sysadmin and can write to /usr/local/ and have to set up things for many users: add a symlink ln -s /usr/local/bin/gcc-8 /usr/local/bin/gcc etc and ask your users to put /usr/local/bin/ in their $PATH before /usr/bin/
BTW, notice that it is explicitly documented that GCC 8 (or others) need to be built outside of its source tree: in Installing GCC you can read:
First, we highly recommend that GCC be built into a separate directory from the sources which does not reside within the source tree.
(the "highly recommend" should be considered as a polite way to say "you absolutely should")
So your ./configure was another mistake.
It could happen that you messed up your system more seriously than you thought (and perhaps you need to reinstall, or to call Redhat support).
PS. I don't know Redhat (used it only in the previous century). My favorite distro is Debian/testing or Debian/unstable (and my computers are desktops, not clusters).
This problem was solved by the following commands
sudo yum install compat-gcc-34-c++
sudo yum install compat-gcc-34-g77
Once this older version of gcc is installed, the latest version, gcc-8.2 was built and the system is no longer messed terribly. It is very healthy and fit.
I installed the C++ compiler MinGW following this tutorial, but when i used the consol commands:
> gcc --version
g++ (GCC) 4.8.1
......
> g++ --version
g++ (GCC) 4.8.1
......
> gdb --version
GNU gdb (GDB) 7.6.1
i dont receive any information and the console prints 'gcc is not recognizable as internal or external command'
When you execute step 3:
Setup environment variable PATH to include "<MINGW_HOME>/bin" where <MINGW_HOME> is the MinGW installed directory that you have chosen in the previous step.
Be aware that changes made to your path in the control panel don't affect existing consoles.
You need to open up a new console for the path to affect it.
The other possibility is that you've modified the path in a console you were working in but this is the wrong way to do it, since that path will not affect future consoles.
You most likely missed this step:
Setup environment variable PATH to include "<MINGW_HOME>/bin" where <MINGW_HOME> is the MinGW installed directory that you have chosen in the previous step.
What is the output of this command?
echo $PATH
If it does not include "<MINGW_HOME>/bin", you need to make the necessary adjustment.
Besides, that tutorial is somewhat dated. Cygwin Ports does include packages for MinGW, plus precompiled libraries, available from Cygwin's setup.exe. The packages are:
mingw64-i686-gcc
mingw64-i686-gcc-g++
or
mingw64-x86-gcc
mingw64-x86-gcc-g++
depending on your architecture. If you use those packages, the compiler will be installed in /usr/bin (which already is in your PATH), and you can access it (e.g. as i686-w64-mingw32-gcc) right away.
So I am a new programmer and I just installed XCode on my Macbook to get the GCC. I think Xcode is the only way for getting GCC on OSX. Now when I run my Hello World application, in C++, g++ comes up saying it is version 4.0.1 but when I look for commands starting with g I also see g++-4.2. Is there any way of making 4.2 default rather than 4.0.1, and also is there a way to updating gcc to the latest version 4.4.0?
EDIT: Ok, so I installed macports and installed gcc4.4 and it shows up on terminal as gcc-mp-4.4 and how do I make it default with gcc_select, like what are the commands and stuff. Thanks.
If you install macports you can install gcc select, and then choose your gcc version.
/opt/local/bin/port install gcc_select
To see your versions use
port select --list gcc
To select a version use
sudo port select --set gcc gcc40
I know it is an old request. But it might still be useful to some. With current versions of MacPorts, you can choose the default gcc version using the port command.
To list the available versions of gcc, use:
$ sudo port select --list gcc
Available versions for gcc:
gcc42
llvm-gcc42
mp-gcc46
none (active)
To set gcc to the MacPorts version:
$ sudo port select --set gcc mp-gcc46
I'm just dropping in to say that using a soft link to accomplish this is a terrible, no-good, horrible idea.
One of the key things about writing software is reproduceability - you want to be able to get the same results every time. These systems are so complex that you want to reduce all invisible sources of error.
Having a soft link is an invisible source of error. It's the sort of thing you'll forget in a month, then move to a different machine, and wonder why you are getting different results - or, you'll try to upgrade your system, and you'll get weird errors because it's not expecting a softlink there.
Moreover, this isn't guaranteed to work - in particular, it's not clear that you will get the correct system include files, which have certainly changed between iterations of gcc.
gcc_select is a systematic way of doing the same thing which will work predictably, or in the very worst case you can file a bug report and get an eventual fix or fix it yourself.
Unfortunately :-( gcc_select does not affect which compiler XCode uses so it's not the way to go if you need to work in XCode (which I do). I still don't know what that way might be.
The following recipe using Homebrew worked for me to update to gcc/g++ 4.7:
$ brew tap SynthiNet/synthinet
$ brew install gcc47
Found it on a post here.
use "gcc_select -l"
>
gcc_select -l
gcc40 mp-gcc44
>
gcc_select mp-gcc44
You can have multiple versions of GCC on your box, to select the one you want to use call it with full path, e.g. instead of g++ use full path /usr/bin/g++ on command line (depends where your gcc lives).
For compiling projects it depends what system do you use, I'm not sure about Xcode (I'm happy with default atm) but when you use Makefiles you can set GXX=/usr/bin/g++ and so on.
EDIT
There's now a xcrun script that can be queried to select appropriate version of build tools on mac. Apart from man xcrun I've googled this explanation about xcode and command line tools which pretty much summarizes how to use it.
in /usr/bin type
sudo ln -s -f g++-4.2 g++
sudo ln -s -f gcc-4.2 gcc
That should do it.
You can install your GCC manually
either through
sudo port install gcc46
or your download the source code from one of the mirrors from here for example here
tar xzvf gcc-4.6.0.tar.gz
cd gcc-4.6.0
./configure
make
well if you have multiple version, then through you can choose one
port select --list gcc
remember port on mac is called macport https://www.macports.org/install.php and add add the bin into your path export PATH=$PATH:/opt/local/bin
Whatever Apple ships as the default gcc in xcode (4.2.1 on 10.6, 4.0.1 before) is well tested (and maintained) by the apple guys and the "standard" to build software with on OS X. Everything else is not, so think twice if you want to develop software, or be gcc/OS X beta tester.
Not a question, I've just scoured the internet in search of a solution for this problem and thought I'd share it with the good folks of SO. I'll put it in plain terms so that it's accessible to newbs. :) (Apologies if this is the wrong place -- just trying to be helpful.)
This issue occurs with almost any user OS X Snow Leopard who tries to use the Eclipse C/C++ IDE, but is particularly annoying for the people (like me) who were using the Eclipse C/C++ IDE in Leopard, and were unable to work with Eclipse anymore when they upgraded. The issue occurs When users go to build/compile/link their software. They get the following error:
Launch Failed. Binary Not Found.
Further, the "binaries" branch in the project window on the left is simply nonexistent.
THE PROBLEM: is that GCC 4.2 (the GNU Compiler Collection) that comes with Snow Leopard compiles binaries in 64-bit by default. Unfortunately, the linker that Eclipse uses does not understand 64-bit binaries; it reads 32-bit binaries. There may be other issues here, but in short, they culminate in no binary being generated, at least not one that Eclipse can read, which translates into Eclipse not finding the binaries. Hence the error.
One solution is to add an -arch i686 flag when making the file, but manually making the file every time is annoying. Luckily for us, Snow Leopard also comes with GCC 4.0, which compiles in 32 bits by default. So one solution is merely to link this as the default compiler. This is the way I did it.
THE SOLUTION: The GCCs are in /usr/bin, which is normally a hidden folder, so you can't see it in the Finder unless you explicitly tell the system that you want to see hidden folders. Anyway, what you want to do is go to the /usr/bin folder and delete the path that links the GCC command with GCC 4.2 and add a path that links the GCC command with GCC 4.0. In other words, when you or Eclipse try to access GCC, we want the command to go to the compiler that builds in 32 bits by default, so that the linker can read the files; we do not want it to go to the compiler that compiles in 64 bits.
The best way to do this is to go to Applications/Utilities, and select the app called Terminal. A text prompt should come up. It should say something like "(Computer Name):~ (Username)$ " (with a space for you user input at the end). The way to accomplish the tasks above is to enter the following commands, entering each one in sequence VERBATIM, and pressing enter after each individual line.
cd /usr/bin
rm cc gcc c++ g++
ln -s gcc-4.0 cc
ln -s gcc-4.0 gcc
ln -s c++-4.0 c++
ln -s g++-4.0 g++
Like me, you will probably get an error that tells you you don't have permission to access these files. If so, try the following commands instead:
cd /usr/bin
sudo rm cc gcc c++ g++
sudo ln -s gcc-4.0 cc
sudo ln -s gcc-4.0 gcc
sudo ln -s c++-4.0 c++
sudo ln -s g++-4.0 g++
Sudo may prompt you for a password. If you've never used sudo before, try just pressing enter. If that doesn't work, try the password for your main admin account.
OTHER POSSIBLE SOLUTIONS
You may be able to enter build variables into Eclipse. I tried this, but I don't know enough about it. If you want to feel it out, the flag you will probably need is -arch i686. In earnest, GCC-4.0 worked for me all this time, and I don't see any reason to switch now. There may be a way to alter the default for the compiler itself, but once again, I don't know enough about it.
Hope this has been helpful and informative. Good coding!
just for records, after struggling for 30 minutes, i solved this problem on lion (mac 10.7) by selecting Mach-O 64 Parser and Elf Parser under : Project Menu -> Properties->C/c++ Build->Settings->Binary Parsers tab (first tab, or third tab on Eclipse Version: 3.7.2) [ while listening to sweet escape by gwen stefani lol ].
I had been getting the same message of
Launch Failed. Binary Not Found.
because I had not realized I needed to ctrl-click on the project folder and select "Build Project." This does not have to be done in Java projects in Eclipse, so other beginners like myself might have the same problem.
as mentioned, this can be accomplished simply by adding the necessary flag in eclipse.
to do so open the properties window, then go to "c/c++ build" > "settings". In the tree view on the right go to "miscellaneous" of "MacOS X C Linker" and "GCC C compiler" and append in the textbox labelled ~"flags" : "-arch i686"
I'm running Mac OSX 10.6.8, and my Eclipse had the Cross GCC toolchain installed. So, I did this:
Under the Properties for the project, select C/C++ Build -> Tool Chain editor.
Change the Current toolchain from Cross GCC to MacOSX GCC.
I also changed the Current builder to CDT Internal Builder. (I'm not sure if this mattered.)
I left all the stuff under Settings alone.
Rebuild. You should see a binary with the same name as your project in the Debug folder of your project.
Oh, one more thing Don't forget to make a record of your links before you change them! If you don't want to change the system wide settings, add a directory into PATH before /usr/bin (say, $HOME/bin), and make the symlinks there If you want to change back, here's the code I would use:
cd /usr/bin
sudo rm cc gcc c++ g++
sudo ln -s gcc-4.2 cc
sudo ln -s gcc-4.2 gcc
sudo ln -s c++-4.2 c++
sudo ln -s g++-4.2 g++
You'll want to check your /usr/bin and look for a file that's like "gcc-4.x". If it isn't 4.0 or 4.2, substitute the version numbers above for the version number that you have.
EDIT: Oh, I also have trouble running the 64-bit carbon Eclipse if I'm using GCC-4.0. However, the 32-bit Carbon works great.
I got a program called gcc_select that has a prefs file somewhere and will allow you swap back and forth between multiple versions of gcc...
I think I got it from macports, but I'm not sure.
"as mentioned, this can be accomplished simply by adding the necessary flag in eclipse.
to do so open the properties window, then go to "c/c++ build" > "settings". In the tree view on the right go to "miscellaneous" of "MacOS X C Linker" and "GCC C compiler" and append in the textbox labelled ~"flags" : "-arch i686""
Note that, if you go this route, you can easily check your processor's architecture by invoking the command
uname -p
in the Bash terminal (i.e. Terminal.app) and changing "-arch i686" to "-arch -i386".
Instead go to Project -> Properties;
Select C/C++ Build -> Settings;
Under Tool Settings change the C++ compiler and Linker commands from g++ to g++-4.0. If you are still getting any errors change the c compiler also to gcc-4.0. I changed the C compiler settings also to be on the safe side. Everything is working perfectly fine for me.
Hi I installed Eclipse 32 bit and works perfectly so far on mac Mountain lion.
I was getting the Binary not found on compile but now with the 32 bit Eclipse no problem.
Simply remove "Debug" folder from your project and then run "Build project".