Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to change include path for clang

When building with clang, it seems to be using gcc4.4.4 version of include files, while I want it to use newer ones.

[ ~ ] locate move.h
/home/apps/gcc_versions/gcc-4_8_install/include/c++/4.8.3/bits/move.h
/usr/include/c++/4.4.4/bits/move.h
/usr/local/include/c++/4.7.1/bits/move.h

gcc path :

`gcc -print-prog-name=cc1plus` -v
ignoring nonexistent directory "/apps/gcc_versions/gcc-4_8_install/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /apps/gcc_versions/gcc-4_8_install/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/../../../../include/c++/4.8.3
 /apps/gcc_versions/gcc-4_8_install/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/../../../../include/c++/4.8.3/x86_64-unknown-linux-gnu
 /apps/gcc_versions/gcc-4_8_install/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/../../../../include/c++/4.8.3/backward
 /apps/gcc_versions/gcc-4_8_install/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/include
 /usr/local/include
 /apps/gcc_versions/gcc-4_8_install/include
 /apps/gcc_versions/gcc-4_8_install/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/include-fixed
 /usr/include
End of search list.

And gcc includes work fine But with clang it fails

[ ~ ] clang -v
clang version 3.5 (http://llvm.org/git/clang.git 8e674ff884113429b53d23b18409caf67aaec1b7) (http://llvm.org/git/llvm.git 7add5421a686877e0aa87616b92b1f5a85c6feee)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/4.4.4
Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/4.4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.7
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.7

I am a newbie at this and please suggest if some info is missing that would help to resolve this.

like image 666
Humble Debugger Avatar asked Jan 26 '14 12:01

Humble Debugger


People also ask

Is GCC better than Clang?

GCC supports more traditional languages than Clang and LLVM, such as Ada, Fortran, and Go. GCC supports more less-popular architectures, and supported RISC-V earlier than Clang and LLVM. GCC supports more language extensions and more assembly language features than Clang and LLVM.

How do I use GCC instead of Clang?

If you want to use clang instead of GCC, you can add -DCMAKE_C_COMPILER=/path/to/clang -DCMAKE_CXX_COMPILER=/path/to/clang++ . You can also use ccmake , which provides a curses interface to configure CMake variables.

Does LLVM include Clang?

Clang is released as part of regular LLVM releases. You can download the release versions from https://llvm.org/releases/. Clang is also provided in all major BSD or GNU/Linux distributions as part of their respective packaging systems. From Xcode 4.2, Clang is the default compiler for Mac OS X.

Is GCC the same as Clang?

Clang is designed as an API from its inception, allowing it to be reused by source analysis tools, refactoring, IDEs (etc) as well as for code generation. GCC is built as a monolithic static compiler, which makes it extremely difficult to use as an API and integrate into other tools.


1 Answers

Try compiling as following,

clang++ -isystem /SOMEPATH/gcc-4.9.2/include/c++/4.9.2 -I/SOMEPATH/gcc-4.9.2/include/c++/4.9.2/x86_64-unknown-linux-gnu a.cpp

like image 58
Zizheng Wu Avatar answered Oct 07 '22 00:10

Zizheng Wu