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
Related
I have installed clang on my Windows 10 machine.
$ clang --version
clang version 6.0.1 (tags/RELEASE_601/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
With it, I can compile C and C++ sources and generate object files, and use lib.exe to create libraries of them.
When it's time to link it into a binary, to my surprise, clang is creating a lib/exp output, not an executable?
Why does clang think it should be creating a library, not an executable?
clang++ -oarmor XWin/main.o -lSDL2main -lpi -ldblunt -lsino -lbase -L. -L ../../src/sino -L MSWin/libs/SDL/lib ../../src/Chipmunk2D/build.release/x64/Release/chipmunk.lib MSWin/libs/OpenAL/lib/OpenAL32.lib -lSDL2 -lOpenGL32
Creating library armor.lib and object armor.exp
LINK : fatal error LNK1561: entry point must be defined
clang++.exe: error: linker command failed with exit code 1561 (use -v to see invocation)
In UNIX, clang will by default create binaries, not libraries?
Check this link -
https://metricpanda.com/rival-fortress-update-27-compiling-with-clang-on-windows
There are currently two flavors of Clang that work on Windows: vanilla LLVM Clang and Clang/C2 with Microsoft Codegen.
I'm trying to use the Undefined Behavior Sanitizer by building like this
gcc -fsanitize=undefined add.c -o add
also
clang -fsanitize=undefined -O add.c -o add
In both cases, I'm getting a file not found error:
ld: file not found: /Library/Developer/CommandLineTools/usr/bin/../lib/clang/8.0.0/lib/darwin/libclang_rt.ubsan_osx_dynamic.dylib
This is the output I get when running gcc -v and clang -v
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
According to this news release, it is available in GCC and also the original homepage for it says it's been merged into LLVM. The linked to article says GCC 4.9 has it, which I assume I have (at least --the version numbering seems different but the article was written a few years ago and I have updated my system several times).
Question: how can I build an executable to use UBSan?
According to blog Friday Q&A 2015-07-03: Address Sanitizer
by Mike Ash:
Any idea why Apple clang doesn't support -fsanitize=undefined?
When I try that I get:
clang -fsanitize=undefined ub.c
...
ld: file not found: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/
bin/../lib/clang/8.0.0/lib/darwin/libclang_rt.ubsan_osx_dynamic.dylib
Spencer at 2016-12-21 01:23:59:
If you use -fsanitize=address,undefined it works. Hopefully this
helps anyone else who finds this post search for that error like I did.
Its not an ideal solution for us since they are separate components, and we have limited control over the environment and tools. We had to suspend some Address Sanitizer testing because Asan produces incorrect results with GCC inline assembly and use of ebp/rbp as a general purpose register. And here, the environment and tools are provided by Travis CI.
A bug report was filed with LLVM at Issue 33201, Apple Clang bundled with Xcode 8 does not reject -fsanitize=undefined when it should. It may be closed as off-topic since its an Apple Clang bug (we don't have an iTunes account to file the bug with Apple).
In order to use the undefined behavior sanitizer, I had to install and build LLVM with clang as well as libcxx and libcxxabi, even though my MacOS already came with a version of clang. (with the result that I now I have two versions of clang installed on my computer). From the llvm getting started page
cd where-you-want-llvm-to-live
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd where-you-want-llvm-to-live
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd where-you-want-llvm-to-live
svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi
Now, I can use the undefined behavior sanitizer by running
/usr/local/bin/clang -fsanitize=undefined -O add.c -o add
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.
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
After a very long time away from C programming, I've decided to try and get familiar with it again. I am trying to compile a hello.c program but am having problems. Here's the code:
#include <stdio.h>
main()
{
printf("Hello\n");
}
And here's the output from gcc:
$ gcc -o hello hello.c
hello.c:1:19: error: stdio.h: No such file or directory
hello.c: In function ‘main’:
hello.c:4: warning: incompatible implicit declaration of built-in function ‘printf’
$
I am working on a Mac running Snow Leopard (10.6.8) and Xcode 3.2.6.
Here's the 'gcc -v' output:
$ gcc -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5666.3~6/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)
$
gcc is not able to find stdio.h which is located in /Developer/SDKs/MacOSX10.6.sdk/usr/include. Wondering about how to set an environment variable so I don't have to specify the include path on the command line. I get another error when I specify it on the command line:
$ gcc -I/Developer/SDKs/MacOSX10.6.sdk/usr/include -o hello hello.c
ld: library not found for -lcrt1.10.6.o
collect2: ld returned 1 exit status
$
My LD_LIBRARY_PATH environment variable is:
$ echo $LD_LIBRARY_PATH
/Developer/SDKs/MacOSX10.6.sdk/usr/lib
$
Any help is appreciated.
Thanks,
Keith
You need to re-run the Xcode installer and check the option for UNIX Development:
Without this option you can still use Xcode but you will not get /usr/include etc for gcc command-line builds.
You already have an answer for your particular problem, but I have seen this problem on OS X for a different reason, so this may be helpful to other people.
If you have tried installing a custom compiled version of GCC and it is in /usr/local/bin or you have added a PATH entry to /opt/sw or something similar, you can get this error.
Possible reasons for having the custom GCC but no headers are:
You tried to remove the custom compiled version but forgot to delete the gcc binary.
You used the wrong configure options when building the custom GCC.
You installed the header files to the wrong directory. (Very similar to the last option.)