compiling C++ with clang++

I’m trying to compile a fairly simple C++ program with clang++. I get the following error message

vec.cpp:1:10: fatal error: ‘iostream’ file not found
#include
^
1 diagnostic generated.

After looking around a bit on the clag website I came across this wonderful hack

  • Look for the comment “FIXME: temporary hack: hard-coded paths” in clang/lib/Frontend/InitHeaderSearch.cpp and change the lines below to include that path.

After adding the relevant paths I still get this linker error

/tmp/cc-TKUPKY.o:(.gnu.linkonce.r._ZZ18__gthread_active_pvE20__gthread_active_ptr+0x0): undefined reference to `__gthrw_pthread_cancel(unsigned long)’
collect2: ld returned 1 exit status
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Has anyone come across a similar situation? thanks,

Salman

this was recently fixed... either update your clang/llvm or use clang++ -O2

Salman Pervez wrote:

/tmp/cc-TKUPKY.o:(.gnu.linkonce.r._ZZ18__gthread_active_pvE20__gthread_active_ptr+0x0): undefined reference to `__gthrw_pthread_cancel(unsigned long)'
collect2: ld returned 1 exit status
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Has anyone come across a similar situation?

Some time ago clang++ gets support of attribute weakref. After that it starts to report this error.

I think support of weakrefs is incomplete or broken.

Use -D_GLIBCXX__PTHREADS to workaround the problem.

I think support of weakrefs is incomplete or broken.

It is possible. If you have a testcase please report the bug. I will
take a look as soon as I can.

Cheers,

I dont think the problem I am facing is related to weakrefs. Here's a simple C++ file I'd like to compile with clang++.

#include <iostream>

using namespace std;

int main() {

   cout << "Hello World" << endl;
   return 0;
}

And I get the following error message.

vec1.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
          ^
1 diagnostic generated.

It looks like clang is having trouble locating some necessary header files. I know its a newbie question but I'll appreciate any help on this. thanks,

Salman

What platform are you on? It may not be able to find iostream because it's looking in the wrong set of places (or no place) for your system.

-eric

I'm using Gentoo Linux, 64 bit.

Salman

I need more information :slight_smile:

Where does g++ think iostream is? I.e. what is it searching for headers? You can get this information via -v when compiling.

-eric

Here's the whole dump!

Configured with: /scratch/portage/tmp/portage/sys-devel/gcc-4.3.2-r3/work/gcc-4.3.2/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.3.2 --includedir=/us\
r/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.3.2 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.3.2/man --infodir=/us\
r/share/gcc-data/x86_64-pc-linux-gnu/4.3.2/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-li\
nux-gnu --disable-altivec --disable-fixed-point --disable-nls --with-system-zlib --disable-checking --disable-werror --enable-secureplt --enable-multilib --enable-libmudfla\
p --disable-libssp --enable-libgomp --enable-java-awt=gtk --enable-languages=c,c++,java,treelang,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enab\
le-clocale=gnu --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.3.2-r3 p1.6, pie-10.1.5'
Thread model: posix
gcc version 4.3.2 (Gentoo 4.3.2-r3 p1.6, pie-10.1.5)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic'
  /usr/libexec/gcc/x86_64-pc-linux-gnu/4.3.2/cc1plus -quiet -v -D_GNU_SOURCE vec1.cpp -quiet -dumpbase vec1.cpp -mtune=generic -auxbase vec1 -version -o /tmp/ccQ7Ek9N.s
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
  /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4
  /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4/x86_64-pc-linux-gnu
  /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4/backward
  /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include
  /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include-fixed
  /usr/include
End of search list.
GNU C++ (Gentoo 4.3.2-r3 p1.6, pie-10.1.5) version 4.3.2 (x86_64-pc-linux-gnu)
         compiled by GNU C version 4.3.2, GMP version 4.2.4, MPFR version 2.4.1-p1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: e6963323901a51065250c11068e53fdf
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic'
  /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../x86_64-pc-linux-gnu/bin/as -V -Qy -o /tmp/cciEVqNH.o /tmp/ccQ7Ek9N.s
GNU assembler version 2.18 (x86_64-pc-linux-gnu) using BFD version (GNU Binutils) 2.18

COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.3.2/:/usr/libexec/gcc/x86_64-pc-linux-gnu/4.3.2/:/usr/libexec/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu\
/4.3.2/:/usr/lib/gcc/x86_64-pc-linux-gnu/:/usr/libexec/gcc/x86_64-pc-linux-gnu/4.3.2/:/usr/libexec/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/:/usr/lib\
/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../x86_64-pc-linux-gnu/bin/
LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../lib64/:/lib/../lib64/:/usr/l\
ib/../lib64/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../x86_64-pc-linux-gnu/lib/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic'
  /usr/libexec/gcc/x86_64-pc-linux-gnu/4.3.2/collect2 --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../.\
./../lib64/crt1.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../lib64/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/crtbegin.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2\
  -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/\
4.3.2/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../.. /tmp/cciEVqNH.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64\
-pc-linux-gnu/4.3.2/crtend.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../lib64/crtn.o

are these the relevant paths?

/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4/x86_64-pc-linux-gnu
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4/backward
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include-fixed

How do I tell clang where these live?

Take a look at the configure options:

--with-c-include-dirs
--with-cxx-include-root
--with-cxx-include-arch
--with-cxx-include-32bit-dir
--with-cxx-include-64bit-dir

Salman

Cheers,

are these the relevant paths?

/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4/x86_64-pc-linux-gnu
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4/backward
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include-fixed

Yep.

How do I tell clang where these live?

Think this should work. Can you apply this and see if it works for you? If not, please run with -v and tell me where clang is looking :slight_smile:

-eric

gentoo.diff.txt (737 Bytes)

Are we trying to use these instead of updating InitHeaderSearch now?

-eric

Are we trying to use these instead of updating InitHeaderSearch now?

I have no idea which is the preferred way. I usually use the configure options.

There was some discussion on how to implement support for multiple
configurations, but I am not sure what is the status on that.

-eric

Cheers,

Well, there's some progress but the error message is still the same. Here's the output I get with -v

clang version 1.1 (trunk 97606)
Target: x86_64-unknown-linux-gnu
Thread model: posix
  "/scratch/spervez/llvm-top/llvm/Debug/bin/clang" -cc1 -triple x86_64-unknown-linux-gnu -S -disable-free -main-file-name vec1.cpp -mrelocation-model static -mdisable-fp-eli\
m -mconstructor-aliases -munwind-tables -target-cpu x86-64 -v -resource-dir /scratch/spervez/llvm-top/llvm/Debug/lib/clang/1.1 -fmessage-length 86 -fexceptions -fgnu-runtim\
e -fdiagnostics-show-option -o /tmp/cc-RWWYw2.s -x c++ vec1.cpp
clang -cc1 version 1.1 based upon llvm 2.7svn hosted on x86_64-unknown-linux-gnu
ignoring nonexistent directory "/usr/include/c++/4.4.3"
ignoring nonexistent directory "/usr/include/c++/4.4.3/x86_64-pc-linux-gnu/"
ignoring nonexistent directory "/usr/include/c++/4.4.3/backward"
ignoring nonexistent directory "/usr/include/c++/4.4.3"
ignoring nonexistent directory "/usr/include/c++/4.4.3/i686-pc-linux-gnu/"
ignoring nonexistent directory "/usr/include/c++/4.4.3/backward"
ignoring nonexistent directory "/usr/include/c++/4.4"
ignoring nonexistent directory "/usr/include/c++/4.4/x86_64-linux-gnu/"
ignoring nonexistent directory "/usr/include/c++/4.4/backward"
ignoring nonexistent directory "/usr/include/c++/4.4"
ignoring nonexistent directory "/usr/include/c++/4.4/i486-linux-gnu/"
ignoring nonexistent directory "/usr/include/c++/4.4/backward"
....... insert similar output
ignoring nonexistent directory "/usr/include/c++/4.4/backward"
ignoring nonexistent directory "/usr/include/c++/4.4"
ignoring nonexistent directory "/usr/include/c++/4.4/x86_64-suse-linux/"
ignoring nonexistent directory "/usr/include/c++/4.4/backward"
ignoring nonexistent directory "/usr/include/c++/4.3.1"
ignoring nonexistent directory "/usr/include/c++/4.3.1/i686-pc-linux-gnu/"
ignoring nonexistent directory "/usr/include/c++/4.3.1/backward"
ignoring nonexistent directory "/usr/include/c++/4.3.1"
ignoring nonexistent directory "/usr/include/c++/4.3.1/x86_64-unknown-linux-gnu/"
ignoring nonexistent directory "/usr/include/c++/4.3.1/backward"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/i686-pc-linux-gnu/"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/backward"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/i686-pc-linux-gnu/"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/backward"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/i686-pc-linux-gnu/"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/backward"
ignoring nonexistent directory "/usr/include/c++/4.3"
ignoring nonexistent directory "/usr/include/c++/4.3/i486-pc-linux-gnu/"
ignoring nonexistent directory "/usr/include/c++/4.3/backward"
ignoring nonexistent directory "/usr/include/c++/4.3"
ignoring nonexistent directory "/usr/include/c++/4.3/i486-linux-gnu/"
ignoring nonexistent directory "/usr/include/c++/4.3/backward"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/i686-pc-linux-gnu/"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/backward"
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
  /scratch/spervez/llvm-top/llvm/Debug/lib/clang/1.1/include
  /usr/include
End of search list.
vec1.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
          ^
1 diagnostic generated.

Are you sure you rebuilt? After these:

ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/i686-pc-linux-gnu/"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/backward"

should be a:

/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4/x86_64-pc-linux-gnu

-eric

oops…I did rebuild but wasnt in the top level dir. Here’s what I get after rebuilding.

/scratch/spervez/llvm-top/llvm/Debug/lib/clang/1.1/include
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g+±v4
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g+±v4/x86_64-pc-linux-gnu
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g+±v4/backward
/usr/include
End of search list.
In file included from vec1.cpp:1:
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g+±v4/iostream:44:
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g+±v4/ostream:44:
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g+±v4/ios:43:
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g+±v4/iosfwd:46:
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g+±v4/bits/postypes.h:46:
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g+±v4/cwchar:48:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g+±v4/cstddef:47:15: fatal error:
’stddef.h’ file not found
#include_next <stddef.h>
^
1 diagnostic generated.

OK. Where's stddef.h on your system? On mine it's in /usr/include :slight_smile:

-eric

usr/src/linux-2.6.29/include/linux/stddef.h
/usr/include/linux/stddef.h
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/stddef.h

Salman

usr/src/linux-2.6.29/include/linux/stddef.h
/usr/include/linux/stddef.h
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/stddef.h

Hunh. It's amazing anything works on some linux boxes - yours isn't the only one.

Anyhow, new patch. Revert the old one and apply this.

-eric

gentoo.diff.txt (1.01 KB)

OK, solved. thanks for all the help!

Salman