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
Related
I'm trying to cross-compile from Linux (Fedora 29) an Ada program with Windows as target. I have no knowledge about compilation and the Gnat project manager doc couldn't help the noob I am.
I would prefer to use switches inside the project file and keep the command the simplest possible. What should I do?
I tried gprbuild -P logfilter.gpr --target=Windows which leads to
Error: no compiler found for language 'c', target = Windows, default runtime
Error: no compiler found for language 'ada', target = Windows, default runtime
logfilter.gpr:3:09: warning: no compiler specified for language "Ada", ignoring all its sources
logfilter.gpr:7:19: "log_filter_main.adb" is not a source of project "logfilter"
gprbuild: problems with main sources
Here is my gprconfig:
prconfig has found the following compilers on your PATH.
Only those matching the target and the selected compilers are displayed.
1. GNAT for Ada in /usr/bin/ version 8.3 (default runtime)
2. GCC-ASM for Asm in /usr/bin/ version 8.3.1
3. GCC-ASM for Asm2 in /usr/bin/ version 8.3.1
4. GCC-ASM for Asm_Cpp in /usr/bin/ version 8.3.1
5. LLVM for C in /usr/bin/ version 7.0.1
6. GCC for C in /usr/bin/ version 8.3.1
7. G++ for C++ in /usr/bin/ version 8.3.1
and my gprconfig --show-targets:
List of targets supported by a compiler:
x86_64-redhat-linux
x86_64-unknown-linux-gnu
here is my file.gpr:
with "../../lib/gnat/gtkada";
project LogFilter is
for Source_Dirs use ("src");
for Object_Dir use "obj";
for Exec_Dir use "exec";
for Main use ("log_filter_main.adb");
package Builder is
for Executable ("main.adb") use "Logs_Filter";
end Builder;
package Compiler is
for Switches ("ada") use ("-gnat2012");
end Compiler;
end Logfilter;
Once I did this with Fedora 24. But this required to build a cross compiler. I still have a docker image
and patches for fedora packages
I filled a request on fedora to include ada in windows in cross compiler, but they closed it. I'm unable to find the bug number, however.
Tell me if you are interested in fresh version of this or instructions how to use.
Update: I've rebuilt cross for FC29. You can try it this way:
dnf copr enable reznik/ada
dnf install mingw64-gcc-gnat
dnf install gprbuild
sed -i -e 's/-pc-mingw/-w64-mingw/g' /usr/share/gprconfig/*
cat > hello.adb << EOF
with Ada.Text_IO;
procedure Hello is
begin
Ada.Text_IO.Put_Line ("Hello");
end Hello;
EOF
cat > hello.gpr << EOF
project Hello is
for Main use ("hello.adb");
end Hello;
EOF
gprbuild --target=x86_64-w64-mingw32 -P hello.gpr
file hello.exe
hello.exe: PE32+ executable (console) x86-64, for MS Windows
PS: link to copr
As others have pointed out, the issue you're encountering is because you're not using a cross compiler.
Just to clarify something about gprbuild that might make this clearer: gprbuild is just a front-end for the versions of gcc and gnat on your system. Essentially it's just an Ada-specific analogue of make. It processes the project configuration file and works out what parts of the project to be built. From the gprconfig output it looks like you're using the FSF GNAT obtained from the Fedora repos. gprconfig --show-targets is only showing you the targets of the native Linux compilers that it's found in your $PATH.
To solve your problem you'll need to find an Ada compiler targeting Windows. AdaCore provide a pretty decent native Windows compiler if that's an option for you.
I seek some help with 2 Makefiles for 2 different software that are much older than my iMAC machine. I think the software assumes the C compiler to be GCC, while my new iMAC has CLANG as default I think...
I know there are some other threads on this general topic such as at : Compile program using a Makefile with gcc instead of clang
But I wonder if there are Makefile specific modifications for these 2 software that you can suggest I perform. I dont have any experience with modifying Makefiles or flags etc.
The 2 Makefiles and the software that they come from can be all accessed from the folder at Dropbox. Thank you!
My make attempt for mdust looks like this:
Checked http://b110-wiki.dkfz.de/confluence/display/nextrnai/Step-by-step+installation+on+MAC for details on
Installation of mdust
Mdust can be downloaded via this link.
Unpack the file. In the folder created open fastafile.c and delete the third line #include (malloc.h is not needed under Mac OS X, but leads to an error with make). Finally typemake (ignore warnings) which creates the mdust script required by NEXT-RNAi (compilation requires prior installation of Apple Developer Tools / Xcode).
tar -xvzf mdust.tar.gz
cd mdust
emacs fastafile.c (delete line include )
make
So I opened fastafile.c with vi and deleted the
line include
But now, when I try make, I think I see CLANG Vs gcc compiler issues.
DCook04-2:mdust anand$ make
gcc -O2 -Wall -I. -I- -D_REENTRANT -c fastafile.c -o fastafile.o
clang: error: '-I-' not supported, please use -iquote instead
make: *** [fastafile.o] Error 1
My make attempt for RECON may have worked, only warning, no errors per STDOUT. Longer STDOUT, so in folder with link above, and obviously named file.
More info that's hopefully relevant:
DCook04-2:src anand$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
DCook04-2:src anand$ clang -v
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
I am trying to build GraphChi on OS X Yosemite but get the following error:
fatal error: 'omp.h' file not found
From this question - How to include omp.h in OS X? - I learned that Yosemite uses Clang instead of gcc, which does not include omp.h.
$ which gcc
/usr/bin/gcc
$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
Next, I installed gcc via Homebrew
$ brew info gcc
gcc: stable 4.9.2 (bottled)
http://gcc.gnu.org
/usr/local/Cellar/gcc/4.9.2_1 (1092 files, 177M)
Built from source with: --without-multilib
and updated $PATH to include the path to the new gcc version
$ echo $PATH
/usr/local/Cellar/gcc/4.9.2_1:usr/local/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
however, gcc -v and which gcc still point to the old version, and building GraphChi still doesn't work due to the missing omp.h file
Does anyone know what else I need to do?
Update
locate omp.h returned:
/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/lib/gcc/i686-apple-darwin11/4.2.1/include/omp.h
/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.1.0/4.9.2/include/omp.h
/usr/local/Cellar/gfortran/4.8.2/gfortran/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2/include/omp.h
my ~/.profile:
export PATH=/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.1.0/4.9.2/include:/usr/local/Cellar/gcc/4.9.2_1/bin:usr/local/bin:/opt/local/bin:/opt/local/sbin:$PATH
I solved this with installing gcc with homebrew:
brew install gcc --without-multilib
and then building the source code with
CC=gcc-5 CXX=g++-5 cmake ..
CC=gcc-5 CXX=g++-5 make -j7
Once you have installed gcc-4.9 with homebrew, it will automatically be in your path. To use OpenMP, you just need to make sure you are using the newly installed gcc-4.9, and it will be able to find omp.h.
In the case of GraphChi, you will have to go change line 3 of the Makefile to be gcc-4.9. From there, running make should just work. They describe this in their README, but at least the version they describe is out of date https://github.com/GraphChi/graphchi-cpp#problems-compiling-on-mac.
clang does not support OpenMP yet. Also gcc by default links to Apple's LLVM clang compiler (not the GCC installed from brew).
Instead gcc-4.9 would link to GCC. I think if -fopenmp is specified omp.h is included automatically.
It is possible to manually build a version of clang with OpenMP support, see http://clang-omp.github.io
You shouldn't add the include path to PATH; instead, specify it as CFLAGS, including the -I option. You can export the CFLAGS variable, or set it on the fly.
Depending on how you compile things, you could do
CFLAGS=-I/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.1.0/4.9.2/include/omp.h gcc <whatever>
Of course, in this case you can specify it directly on the gcc command (as -I/usr/local/....), but the CFLAGS variable also works with configure (as configure often won't have an option to specify where it should look for specific include files); probably with make, or even for those installing a Python package: CFLAGS=-I... pip install <some-package>.
Other flags to consider are
CXXFLAGS: C++ specific pre-processor flags
LDFLAGS: linker specific flags (e.g. LDFLAGS=-L/some/path/... for linking with dynamic libraries).
CC: specify the C compiler to use. This is an easy way to avoid the built-in gcc alias for clang on OS X. Just use CC=/usr/local/bin/gcc-4 make or similar.
CXX: specify the C++ compiler to use.
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)
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.