use qtcreator with gnu g++4.8 in mac os x - macos

I would like to set g++4.8 as the c++ compiler with qt creator.
I am in a OSX 10.8, QtCreator 2.8.0, and I have installed g++4.8 via homebrew.
I have setted the g++4.8 as the compiler: if I go in Projects > Manage Kits I have the GCC kit as default, and manually inserted a compiler called GCC 4.8, with compiler path /usr/local/Cellar/gcc48/4.8.1/bin/g++-4.8.
You can see it in the screenshots below. I also have /usr/local/Cellar/gcc48/4.8.1/bin in the Build Enviroment > PATH.
But, if I add QMAKE_CXXFLAGS = --version (I know it is dumb and it doesn't compile but it is just for testing) I receive in the "compiler window"
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1
(that is the same output i receive if I launch g++ from the shell) and not
g++-4.8 (GCC) 4.8.1
(that is what i receive if I launch /usr/local/Cellar/gcc48/4.8.1/bin/g++-4.8 from the shell) (and it is what I want too)
I remember that I had this problem in the past, I tried to resolved it hardlinking the g++4.8 to /usr/bin/g++ but it was not resolved (and just messed up everything).
What can I do?

I had the same problem and landed on your question...
Your question is how to make Qt Creator to use g++-4.8 for compilation.
The solution I devised is the following:
Solution
Add the following line somewhere in your project.pro file
QMAKE_CXX = g++-4.8
for instance just above the HEADERS list
Rationale:
The makefile synthesized by qmake uses the variable CXX to determine the C++ compiler.
You can set the value of the variable CXX at the level of the project configuration file by manually editing it.
Pros:
It solves your problem, you will compile your project using g++-4.8 without having to change the g++ compiler for the rest of your environment.
Cons:
You have to manually set that for each project.
Question for Qt developers:
is there a more natural way to set the g++ compiler at the Kit level? If there is not way, that might be a useful functionality to add.

Related

Qt creator - using a custom x86 compiler?

I'm using a x86 toolchain to build the binary in Qt Creator 3.4.0 (opensource) . There is a /usr/bin/gcc and a <path-to-toolchain>/i686-atom-linux-gnu-gcc and I want to use i686-atom-linux-gnu-gcc.
The Compiler path in Build&Run->Compilers->Compiler path correctly set to point to i686-atom-linux-gnu-gcc.
When I try to observe what commands from the Makefile are being executed, it always shows that the compiler is gcc, while it should have a compiler prefix (i686-atom-linux-gnu-gcc).
Update:
The qmake call is called with a parameter -spec linux-g++. However, on the working version, this value corresponds to mkspec in Build&Run->Qt versions->Details.
The correct kit is selected in the project options. Am I missunderstanding something or could it be a bug in Qt Creator?
The issue was doe to the wrong default -spec linux-g++ parameter. Doe to it the generated Makefiles had the default PC toolchain instead of the one selected in the Kit.
After manually adding -spec qws/linux-ptx-g++ in Projects->Additional arguments:, the generated makefile uses the correct compiler.
I got the parameter qws/linux-ptx-g++ from Options->Build&Run->Qt Versions->"your Qt version"->Details->mkspec
This is a trial and error discovered answer, I'll gladly accept another that could explain this behaviour.

Default compiler from llvm-clang to llvm-gcc42 (command line)

I'm trying to compile a project from the command line. The default compiler LLVM-clang and i need to compile with LLVM-gcc42. Switching a compiler in Xcode is really easy. However, on command line it seems to be more problematic. To my understanding "/usr/bin/cc" and "/use/bin/gcc" are used for pointing c/c++ compilers. I noticed that "cc" was linked to "clang" in same directory. So, i changed "cc" to point at "gcc". Did not helped. When i run
$ gcc -v
i get response
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.5.0
How do i change the clang to gcc?
My setup is:
MAC OS X 10.8.5
Xcode 4.6.2
Command line tools
EDIT 13.02.2014
The project is a QT project which uses mixture of third party c/c++ libraries. My task is to write a new objective C lib to it. The project is build with -spec macx-g++ parameter. The configuration scripts can be found /QTROOT/mkspecs/macx-g++ and /QTROOT/mkspecs/common. In g++-base.conf key variables are defined as:
QMAKE_CC = gcc
QMAKE_CXX = g++
Instead of changing links which can affect other programs use the full path to the llvm executables in your build script
e.g. if you have installed the command line tools
QMAKE_CC = /usr/bin/llvm-gcc-4.2
QMAKE_CXX = /usr/bin/llvm-g++-4.2
Okay, nailed the problem. Solution was simple. I deleted the old links from /usr/bin/gcc and /usr/bin/g++ and created new ones pointing to the proper compilers.
gcc -> /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2
and
g++ -> /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/bin/llvm-g++-4.2

Using gcc instead of clang in ghci or ghc

On Mac OSX 10.9, the default c compiler bundled with Xcode is clang. I installed gcc-4.9 with homebrew. Now I have two different gccs, one is clang, the other is gcc. The default is clang.
I want to use gcc when compiling Haskell files with ghc, and I want also gcc when I launch ghci. How to do this change?
Reproducing my directions I've been sharing with haskellers for the past few months via https://gist.github.com/cartazio/7131371
Type ghc --print-libdir
The output will be a path like /Library/Frameworks/GHC.framework/Versions/7.6.3-x86_64/usr/lib/ghc-7.6.3
Go to that directory and edit the settings file.
There'll be a line indicating the path to the C compiler. It'll probably say /bin/gcc
Change that line to /usr/local/bin/gcc-4.8 (or whichever gcc version you brew installed, such as /usr/local/bin/gcc-4.2)

custom built gcc 4.6.0 on ubuntu 11.04 links wrong libstdc++

my custom built gcc 4.6.0, installed in my home directory, on ubuntu 10.04, links the system libstdc++ instead of the custom built one, most of the time (as evidenced by ldd). to be more puzzling, using this newly built gcc, custom compiled openmpi libraries are linked correctly, and this is the only software i have compiled that behaves ok. does anybody have any explanation for this, or a workaround?
thanks
Isn't there an option to statically link the libstdc into the gcc when you configure it? --disable-shared if I understand how it works correctly. Worst case make another compile of gcc with that switch and see if you run into the issue.
I don't know why this isn't detailed more clearly on the GCC website for end-users. The GCC FAQ clearly states this is a common problem wrt libstdc++. Environment variables are troublesome. Wrapping the linker, nobody knows how to do that. Editing /etc/ld.so.conf isn't an option. Adding -Wl,-rpath everywhere, come on. The easiest solution is the specs file. For a typical 64-bit x86 Linux system, go into your custom gcc installation, in dirname `g++ -print-libgcc-file-name`and then run g++ -dumpspecs > specs. Edit that file, find the *link_command: section. After %(link_libgcc) add -rpath /home/user/bin/gcc-9/lib64 (of course use your own path). Or add the same rpath to end of *link: section. Alternatively, configure gcc with --with-specs='%{!static:%x{-rpath=/home/user/bin/gcc9/lib64} %x{-enable-new-dtags}}' . Enjoy your own C++ compiler that generates binaries that just work.
See also:
GCC specs file: how to get the installation path
Linking g++ 4.8 to libstdc++
How to configure libstdc++ with GCC 4.8?

Obtaining GCC for OSX with Developer Tools installed

I want to start working with C++0x. I see that GCC 4.7 has a fair amount of functionality available. I already have XCode 3.2 installed in /Developer
I downloaded: http://fileboar.com/gcc/snapshots/LATEST-4.7/gcc-4.7-20110528.tar.bz2
Can I somehow compile this in /opt/gcc-4.7? How do I then work with my path so I can compile with GCC 4.7 from the command-line but have OSX use the version it needs?
OSX does not need gcc to run - the Developer tools are optional. So you only need to choose between gcc's when you compile. In Xcode you chose explicitly the gcc andin Makefiles you can set $(CC) or similar to the full path.
Alternatively rename the gcc-4.7 gcc to gcc-4.7 and use that so gcc is always the Apple one.
For ease of using multiple C++ compilers I use macports (or fink or homebrew) which will compile the compilers with the correct patches and also has a port select command to switch between the C++ compilers

Resources